<?php

	class Mahasamadhi_proxy extends Model
	{
		public function __construct()
		{
			parent::__construct();
			
			$this->load->model('values/mahasamadhi/Mahasamadhi_registration_value');
		}
						
		//Get Mahasamadhi event year year
		public function getEventYear()
		{
			$currentyear = $this->db->query('
													SELECT		CAST(mse.year AS CHAR(4)) AS current_year
													FROM		ms_event mse
													WHERE mse.ms_event_id = 1
											    ');
												
			return $currentyear->first_row()->current_year;
		}

		public function getEventName( $eventID )
		{
			
			$tmp = $this->db->query('
								SELECT			mse.description
								FROM			ms_event mse
								WHERE			mse.ms_event_id = ' . $eventID  . '
							 ');
							 
			if( $tmp->num_rows() > 0)
				return $tmp->row()->description;
			else
				return "";
		}

		public function getRegistrationCreateDate( $MSRegHistoryId, $curyear )
		{
			
			$tmp = $this->db->query('
												SELECT    	msrh.date_created
												FROM      	ms_reg_history msrh
												WHERE       msrh.ms_reg_history_id = ' . $this->db->escape( $MSRegHistoryId ) . '
												AND			msrh.year = ' . $this->db->escape( $curyear ) . '
											  ');
											  
			if( $tmp->num_rows() > 0)
				return $tmp->row()->date_created;
			else
				return "";
		}

		public function getCase1RegistrationFee( $eventID )
		{
			
			$tmp = $this->db->query('
								SELECT			mse.case1_reg_fee
								FROM			ms_event mse
								WHERE			mse.ms_event_id = ' . $eventID  . '
								AND				mse.enabled = 1
							 ');
							 
			if( $tmp->num_rows() > 0)
				return $tmp->row()->adult_reg_fee;
			else
				return 0;
		}

		public function getCase2RegistrationFee( $eventID )
		{
			
			$tmp = $this->db->query('
								SELECT			mse.case2_reg_fee
								FROM			ms_event mse
								WHERE			mse.ms_event_id = ' . $eventID  . '
								AND				mse.enabled = 1
							 ');
							 
			if( $tmp->num_rows() > 0)
				return $tmp->row()->child_reg_fee;
			else
				return 0;
		}
		
		public function getCase3RegistrationFee( $eventID )
		{
			
			$tmp = $this->db->query('
								SELECT			mse.case3_reg_fee
								FROM			ms_event mse
								WHERE			mse.ms_event_id = ' . $eventID  . '
								AND				mse.enabled = 1
							 ');
							 
			if( $tmp->num_rows() > 0)
				return $tmp->row()->child_reg_fee;
			else
				return 0;
		}
		
		public function getCase4RegistrationFee( $eventID )
		{
			
			$tmp = $this->db->query('
								SELECT			mse.case4_reg_fee
								FROM			ms_event mse
								WHERE			mse.ms_event_id = ' . $eventID  . '
								AND				mse.enabled = 1
							 ');
							 
			if( $tmp->num_rows() > 0)
				return $tmp->row()->child_reg_fee;
			else
				return 0;
		}
		
		public function getBhiksaFee( $eventID )
		{
			
			$tmp = $this->db->query('
								SELECT			mse.bhiksha_fee
								FROM			ms_event mse
								WHERE			mse.ms_event_id = ' . $eventID  . '
								AND				mse.enabled = 1
							 ');
							 
			if( $tmp->num_rows() > 0)
				return $tmp->row()->bhiksha_fee;
			else
				return 0;
		}
		
		public function getArathiFee( $eventID )
		{
			
			$tmp = $this->db->query('
								SELECT			mse.arathi_fee
								FROM			ms_event mse
								WHERE			mse.ms_event_id = ' . $eventID  . '
								AND				mse.enabled = 1
							 ');
							 
			if( $tmp->num_rows() > 0)
				return $tmp->row()->arathi_fee;
			else
				return 0;
		}
		
		//Get total number of people registered for event
		public function getTotalNumReg( $eventID, $curyear )
		{
			
			$tmp = $this->db->query('
								SELECT			IFNULL(SUM(msrh.numtotreg),0) AS totnumreg
								FROM			ms_reg_history msrh
								WHERE			msrh.ms_event_id_fk = ' . $eventID  . '
								AND				msrh.enabled = 1
								AND				msrh.year = ' . $this->db->escape( $curyear ) . '								
							 ');
							 
			if( $tmp->num_rows() > 0)
				return $tmp->row()->totnumreg;
			else
				return 0;
		}

		//Check if date for event has passed
		public function isEventValid( $eventID )
		{
			
			$tmp = $this->db->query('
								SELECT			mse.ms_event_id
								FROM			ms_event mse
								WHERE			mse.enabled = 1
								AND				mse.ms_event_id = ' . $eventID  . '
								AND				NOW() < mse.reg_close_date
							 ');
							 
			if( $tmp->num_rows() > 0)
				return TRUE;
			else
				return FALSE;
		}

		//Generate registration object string based on non-empty key fields in ms_reg_history, ms_reg_person ans ms_reg_sponsor
		public function genMSRegistrationObjectString( $ms_registration_value )
		{
			$objstrarr = array();
						
			//All key data in ms_reg_history
			//-----------------------------
			$mrh_str = "";

			if ($ms_registration_value->getFirstName() != "") $mrh_str = strtolower($ms_registration_value->getFirstName());
			if ($ms_registration_value->getLastName() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getLastName());
			if ($ms_registration_value->getCHYKRefFirstName() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getCHYKRefFirstName());
			if ($ms_registration_value->getCHYKRefLastName() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getCHYKRefLastName());
			if ($ms_registration_value->getEmail() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getEmail());
			if ($ms_registration_value->getPhone() != "") $mrh_str = $mrh_str.$ms_registration_value->getPhone();
			if ($ms_registration_value->getAddress() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getAddress());
			if ($ms_registration_value->getAddress1() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getAddress1());
			if ($ms_registration_value->getCity() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getCity());
			if ($ms_registration_value->getState() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getState());
			if ($ms_registration_value->getCountry() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getCountry());
			if ($ms_registration_value->getZip() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getZip());
			if ($ms_registration_value->getIsTeacher() != 0) $mrh_str = $mrh_str.strval($ms_registration_value->getIsTeacher());
			if ($ms_registration_value->getSpecialNeedsWheelchair() != 0) $mrh_str = $mrh_str.strval($ms_registration_value->getSpecialNeedsWheelchair());
			if ($ms_registration_value->getSpecialNeedsRoom() != 0) $mrh_str = $mrh_str.strval($ms_registration_value->getSpecialNeedsRoom());
			if ($ms_registration_value->getSpecialRequests() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getSpecialRequests());
			if ($ms_registration_value->getRegistrationType() != 0) $mrh_str = $mrh_str.strval($ms_registration_value->getRegistrationType());
			if ($ms_registration_value->getRegistrationCase() != 0) $mrh_str = $mrh_str.strval($ms_registration_value->getRegistrationCase());
			if ($ms_registration_value->getPaymentType() != "") $mrh_str = $mrh_str.$ms_registration_value->getPaymentType();
			if ($ms_registration_value->getCheckNum() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getCheckNum());
			if ($ms_registration_value->getPaymentTransactionID() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getPaymentTransactionID());
			if ($ms_registration_value->getPaymentStatus() != 0) $mrh_str = $mrh_str.strval($ms_registration_value->getPaymentStatus());
			if ($ms_registration_value->getRegistrationFee() > 0.01) $mrh_str = $mrh_str.strval($ms_registration_value->getRegistrationFee());
			if ($ms_registration_value->getSponsorship() > 0.01) $mrh_str = $mrh_str.strval($ms_registration_value->getSponsorship());
			if ($ms_registration_value->getDonation() > 0.01) $mrh_str = $mrh_str.strval($ms_registration_value->getDonation());
			if ($ms_registration_value->getGeneralDiscount() > 0.01) $mrh_str = $mrh_str.strval($ms_registration_value->getGeneralDiscount());
			if ($ms_registration_value->getAmountCommitted() > 0.01) $mrh_str = $mrh_str.strval($ms_registration_value->getAmountCommitted());
			if ($ms_registration_value->getAmountPaid() > 0.01) $mrh_str = $mrh_str.strval($ms_registration_value->getAmountPaid());
			if ($ms_registration_value->getComments() != "") $mrh_str = $mrh_str.strtolower($ms_registration_value->getComments());
			if ($ms_registration_value->getEnabled() != 0) $mrh_str = $mrh_str.strval($ms_registration_value->getEnabled());
			
			$objstrarr['mrhstr'] = $mrh_str;
			//-----------------------------
									
			//All key data in ms_reg_person
			//-----------------------------
			$mrp_str = "";

			$numAdult = $ms_registration_value->getNumAdultRegistered();
			if ($numAdult > 0)
			{
				for($i=0; $i<$ms_registration_value->getNumAdultRegistered(); $i++)
				{
					$adultInfoArr = $ms_registration_value->getAdultInfo();
					$adultRec = $adultInfoArr[$i];
		
					if ($mrp_str == "")
					{
						if ($adultRec["firstname"] != "") $mrp_str = strtolower($adultRec["firstname"]);
					}
					else
					{
						if ($adultRec["firstname"] != "") $mrp_str = $mrp_str.strtolower($adultRec["firstname"]);
					}
						
					if ($adultRec["lastname"] != "") $mrp_str = $mrp_str.strtolower($adultRec["lastname"]);
					if ($adultRec["gender"] != "") $mrp_str = $mrp_str.strtolower($adultRec["gender"]);
					if ($adultRec["dietrest"] != "") $mrp_str = $mrp_str.strtolower($adultRec["dietrest"]);
					//if ($adultRec["allergies"] != "") $mrp_str = $mrp_str.strtolower($adultRec["allergies"]);
				}
			}

			$numChild = $ms_registration_value->getNumChildRegistered();
			if ($numChild > 0)
			{
	
				for($i=0; $i<$ms_registration_value->getNumChildRegistered(); $i++)
				{
					$childInfoArr = $ms_registration_value->getChildInfo();
					$childRec = $childInfoArr[$i];
		
					if ($childRec["firstname"] != "") $mrp_str = $mrp_str.strtolower($childRec["firstname"]);
					if ($childRec["lastname"] != "") $mrp_str = $mrp_str.strtolower($childRec["lastname"]);
					if ($childRec["gender"] != "") $mrp_str = $mrp_str.strtolower($childRec["gender"]);
					if ($childRec["age"] != "") $mrp_str = $mrp_str.strtolower($childRec["age"]);
					if ($childRec["dietrest"] != "") $mrp_str = $mrp_str.strtolower($childRec["dietrest"]);
					//if ($childRec["allergies"] != "") $mrp_str = $mrp_str.strtolower($childRec["allergies"]);
				}
			}

			$numCHYK = $ms_registration_value->getNumCHYKRegistered();
			if ($numCHYK > 0)
			{
				for($i=0; $i<$numCHYK; $i++)
				{
					$chykInfoArr = $ms_registration_value->getCHYKInfo();
					$chykRec = $chykInfoArr[$i];
		
					if ($chykRec["firstname"] != "") $mrp_str = $mrp_str.strtolower($chykRec["firstname"]);
					if ($chykRec["lastname"] != "") $mrp_str = $mrp_str.strtolower($chykRec["lastname"]);
					if ($chykRec["gender"] != "") $mrp_str = $mrp_str.strtolower($chykRec["gender"]);
					if ($chykRec["dietrest"] != "") $mrp_str = $mrp_str.strtolower($chykRec["dietrest"]);
					//if ($chykRec["allergies"] != "") $mrp_str = $mrp_str.strtolower($chykRec["allergies"]);
				}
			}

			$objstrarr['mrpstr'] = $mrp_str;
			//-----------------------------
						
			//All key data in ms_reg_sponsor
			//-----------------------------
			$mrs_str = "";

			if ($ms_registration_value->getNumBiksha() > 0)
			{
				for($i=0; $i<$ms_registration_value->getNumBiksha(); $i++)
				{
					$bikshaInfoArr = $ms_registration_value->getBikshaInfo();
					$bikshaRec = $bikshaInfoArr[$i];
					$dayid = intval($bikshaRec["dayid"]);
					$sessid = intval($bikshaRec["eventid"]);
					if ($dayid != 0) $mrs_str = $mrs_str.strval($dayid);
					if ($sessid != 0) $mrs_str = $mrs_str.strval($sessid);
				}
			}

			if ($ms_registration_value->getNumArathi() > 0)
			{
				for($i=0; $i<$ms_registration_value->getNumArathi(); $i++)
				{
					$arathiInfoArr = $ms_registration_value->getArathiInfo();
					$arathiRec = $arathiInfoArr[$i];
					$dayid = intval($arathiRec["dayid"]);
					$sessid = intval($arathiRec["eventid"]);
					if ($dayid != 0) $mrs_str = $mrs_str.strval($dayid);
					if ($sessid != 0) $mrs_str = $mrs_str.strval($sessid);
				}
			}

			$objstrarr['mrsstr'] = $mrs_str;
			//-----------------------------

			return $objstrarr;
		}

		//Generate Reg Obj hash based on non-empty key fields in ms_reg_history, ms_reg_person ans ms_reg_sponsor
		public function genMSRegistrationObjectHash( $ms_registration_value )
		{
			$objstrarr = $this->genMSRegistrationObjectString( $ms_registration_value );
			
			//echo "MRH_str: ".$objstrarr['mrhstr']."</br>";
			//echo "MRP_str: ".$objstrarr['mrpstr']."</br>";
			//echo "MRS_str: ".$objstrarr['mrsstr']."</br>";
			
			$objstr = "";
			if ($objstrarr['mrhstr'] != "")
				$objstr = $objstrarr['mrhstr'];
			
			if ($objstrarr['mrpstr'] != "")
				$objstr = $objstr.$objstrarr['mrpstr'];

			if ($objstrarr['mrsstr'] != "")
				$objstr = $objstr.$objstrarr['mrsstr'];

			if ($objstr != "")
			{				
				//echo $objstr."</br>";
				//die;
				return hash("sha256",$objstr);
			}
			else	
				return "";
		}

		//Generate Reg Obj component hash based on non-empty key fields in ms_reg_history, ms_reg_person ans ms_reg_sponsor
		public function genMSRegistrationObjectHashArray( $ms_registration_value )
		{
			$objhasharr = array();
			
			$objstrarr = $this->genMSRegistrationObjectString( $ms_registration_value );
			
			if ($objstrarr['mrhstr'] != "")
				$objhasharr['mrh'] = hash("sha256", $objstrarr['mrhstr']);
			else
				$objhasharr['mrh'] = "";
			
			if ($objstrarr['mrpstr'] != "")
				$objhasharr['mrp'] = hash("sha256", $objstrarr['mrpstr']);
			else
				$objhasharr['mrp'] = "";

			if ($objstrarr['mrsstr'] != "")
				$objhasharr['mrs'] = hash("sha256", $objstrarr['mrsstr']);
			else
				$objhasharr['mrs'] = "";

			//echo "MRH_hash: ".$objhasharr['mrh']."</br>";
			//echo "MRP_hash: ".$objhasharr['mrp']."</br>";
			//echo "MRS_hash: ".$objhasharr['mrs']."</br>";
			
			return $objhasharr;
		}

		//Compare component hash values for two Reg Objects
		public function compareMSRegistrationObjects( $ms_registration_value_A,  $ms_registration_value_B )
		{
			$comparehasharr = array();
			
			$objhasharr_A = $this->genMSRegistrationObjectHashArray($ms_registration_value_A);
			$objhasharr_B = $this->genMSRegistrationObjectHashArray($ms_registration_value_B);
			
			if (($objhasharr_A['mrh'] != "") and ($objhasharr_B['mrh'] != ""))
			{
				if ($objhasharr_A['mrh'] == $objhasharr_B['mrh'])
					$comparehasharr['mrh'] = 1;
				else
					$comparehasharr['mrh'] = 0;
			}
			else
			{
				if (($objhasharr_A['mrh'] == "") and ($objhasharr_B['mrh'] == ""))
					$comparehasharr['mrh'] = 1;
				else
					$comparehasharr['mrh'] = 0;					
			}
			
			if (($objhasharr_A['mrp'] != "") and ($objhasharr_B['mrp'] != ""))
			{
				if (strcmp($objhasharr_A['mrp'],$objhasharr_B['mrp']) == 0)
					$comparehasharr['mrp'] = 1;
				else
					$comparehasharr['mrp'] = 0;
			}
			else
			{
				if (($objhasharr_A['mrp'] == "") and ($objhasharr_B['mrp'] == ""))
					$comparehasharr['mrp'] = 1;
				else
					$comparehasharr['mrp'] = 0;					
			}
			
			if (($objhasharr_A['mrs'] != "") and ($objhasharr_B['mrs'] != ""))
			{
				if (strcmp($objhasharr_A['mrs'],$objhasharr_B['mrs']) == 0)
					$comparehasharr['mrs'] = 1;
				else
					$comparehasharr['mrs'] = 0;
			}
			else
			{
				if (($objhasharr_A['mrs'] == "") and ($objhasharr_B['mrs'] == ""))
					$comparehasharr['mrs'] = 1;
				else
					$comparehasharr['mrs'] = 0;					
			}
			
			return $comparehasharr;
		}

		public function insertMSRegistrationPayPal( $ms_registration_value, $curyear, $pay_txn_id, $payresponse, $paystatus)
		{
			$this->load->library('encrypt');
			
			$ms_registration_value = Mahasamadhi_registration_value::cast($ms_registration_value);
			$numtotreg = $ms_registration_value->getTotalNumRegistered();
			//$objstrhash = md5( serialize($ms_registration_value) );
			$ms_registration_value->setPaymentType("paypal");
			$ms_registration_value->setAmountPaid( $ms_registration_value->getAmountCommitted() );
			$ms_registration_value->setPaymentStatus( "1" );	
			$objstrhash = $this->genMSRegistrationObjectHash($ms_registration_value);
			$curdate = date('Y-m-d H:i:s', time());
						
			//Check for same registration already existing
			$tmp = $this->db->query('
													SELECT 		ms_reg_history_id 
													FROM 		ms_reg_history
													WHERE		obj_string_hash = ' . $this->db->escape($objstrhash) . '
												  ');

			if( $tmp->num_rows() == 1 )
			{
				$MSRegHistoryId = $tmp->row()->ms_reg_history_id;
				//Already exists so update with Paypal information
				$tmp = $this->db->query('
											UPDATE 		ms_reg_history 
											SET 		payment_type = ' . $this->db->escape("paypal")  . ',
														payment_transaction_id = ' . $this->db->escape($pay_txn_id)  . ',
														payment_status = 1,
														date_modified = STR_TO_DATE(' . $this->db->escape($curdate)  . ',' . $this->db->escape("%Y-%m-%d %T")  . '),
														amount_committed = ' . $this->db->escape($ms_registration_value->getTotalRegistrationFee())  . ',
														amount_paid = ' . $this->db->escape($ms_registration_value->getTotalRegistrationFee())  . '
											WHERE		obj_string_hash = ' . $this->db->escape($objstrhash) . '
										');
			
				return $MSRegHistoryId;
			}

			//Ensure regcode is unique			
			$numtries = 0;
			$found = true;
			while (($numtries < 10) && $found)
			{
				$regcode = $this->encrypt->get_random_password(5,5,false,false,false);
				
				$tmp = $this->db->query('
									SELECT			mrh.regcode
									FROM			ms_reg_history mrh
									WHERE			mrh.regcode = ' . $this->db->escape( $regcode ) . '
								 ');
			
				if( $tmp->num_rows() <= 0) $found = false;
				
				$numtries++;
			}
			
			if ($found)
			{
				return 0;
			}
			
			$this->db->query('
								INSERT INTO			ms_reg_history
													(
														ms_event_id_fk,
														regcode,
														year,
														first_name,
														last_name,
														chyk_ref_first_name,
														chyk_ref_last_name,
														email,
														phone,
														address,
														address1,
														city,
														state,
														country,
														zip,
														is_teacher,
														sn_wheelchair,
														sn_room,
														sn_requests,
														numtotreg,
														numadultreg,
														numchildreg,
														numchykreg,
														numbiksha,
														numarathi,
														reg_type,
														need_accommodation,
														reg_type_desc,
														reg_case,
														reg_case_desc,
														reg_fee,
														sponsor_amount,
														donation_amount,
														discount_amount,
														payment_type,
														payment_transaction_id,
														enabled,
														date_modified,
														date_created,
														amount_committed,
														amount_paid,
														payment_status,
														payment_response,
														obj_string_hash
													)
								VALUES				(
														' . $this->db->escape($ms_registration_value->getEventID())  . ',
														' . $this->db->escape($regcode)  . ',
														' . $this->db->escape($curyear)  . ',
														' . $this->db->escape($ms_registration_value->getFirstName())  . ',
														' . $this->db->escape($ms_registration_value->getLastName())  . ',
														' . $this->db->escape($ms_registration_value->getCHYKRefFirstName())  . ',
														' . $this->db->escape($ms_registration_value->getCHYKRefLastName())  . ',
														' . $this->db->escape($ms_registration_value->getEmail())  . ',
														' . $this->db->escape($ms_registration_value->getPhone())  . ',
														' . $this->db->escape($ms_registration_value->getAddress())  . ',
														' . $this->db->escape($ms_registration_value->getAddress1())  . ',
														' . $this->db->escape($ms_registration_value->getCity())  . ',
														' . $this->db->escape($ms_registration_value->getState())  . ',
														' . $this->db->escape($ms_registration_value->getCountry())  . ',
														' . $this->db->escape($ms_registration_value->getZip())  . ',
														' . $this->db->escape($ms_registration_value->getIsTeacher())  . ',
														' . $this->db->escape($ms_registration_value->getSpecialNeedsWheelchair())  . ',
														' . $this->db->escape($ms_registration_value->getSpecialNeedsRoom())  . ',
														' . $this->db->escape($ms_registration_value->getSpecialRequests())  . ',
														' . $this->db->escape($numtotreg)  . ',
														' . $this->db->escape($ms_registration_value->getNumAdultRegistered())  . ',
														' . $this->db->escape($ms_registration_value->getNumChildRegistered())  . ',
														' . $this->db->escape($ms_registration_value->getNumCHYKRegistered())  . ',
														' . $this->db->escape($ms_registration_value->getNumBiksha())  . ',
														' . $this->db->escape($ms_registration_value->getNumArathi())  . ',
														' . $this->db->escape($ms_registration_value->getRegistrationType())  . ',
														' . $this->db->escape($ms_registration_value->getNeedAccommodation())  . ',
														' . $this->db->escape($ms_registration_value->getRegistrationTypeDescription())  . ',
														' . $this->db->escape($ms_registration_value->getRegistrationCase())  . ',
														' . $this->db->escape($ms_registration_value->getRegistrationCaseDescription())  . ',
														' . $this->db->escape($ms_registration_value->getRegistrationFee())  . ',
														' . $this->db->escape($ms_registration_value->getSponsorship())  . ',
														' . $this->db->escape($ms_registration_value->getDonation())  . ',
														0,
														' . $this->db->escape("paypal")  . ',
														' . $this->db->escape($pay_txn_id)  . ',
														1,
														STR_TO_DATE(' . $this->db->escape($curdate)  . ',' . $this->db->escape("%Y-%m-%d %T")  . '),
														STR_TO_DATE(' . $this->db->escape($curdate)  . ',' . $this->db->escape("%Y-%m-%d %T")  . '),
														' . $this->db->escape($ms_registration_value->getTotalRegistrationFee())  . ',
														' . $this->db->escape($ms_registration_value->getTotalRegistrationFee())  . ',
														' . $this->db->escape($paystatus)  . ',
														' . $this->db->escape($payresponse)  . ',
														' . $this->db->escape($objstrhash)  . '														
													)
							 ');
			
			$tmp = $this->db->query('
													SELECT 		ms_reg_history_id 
													FROM 		ms_reg_history
													WHERE		obj_string_hash = ' . $this->db->escape($objstrhash) . '
												  ');

			if( $tmp->num_rows() == 1 )
			{
				$MSRegHistoryId = $tmp->row()->ms_reg_history_id;
			}
			else
				$MSRegHistoryId = 0;
				
			if ($MSRegHistoryId > 0)
			{
				//Insert all adult info
				$adultInfoArr = $ms_registration_value->getAdultInfo();
				for($i=0; $i<$ms_registration_value->getNumAdultRegistered(); $i++)
				{
					$adultRec = $adultInfoArr[$i];
					
					$this->db->query('
						INSERT INTO			ms_reg_person
											(
												ms_reg_history_id_fk,
												ms_person_id,
												ms_person_type,
												first_name,
												last_name,
												gender,
												diet_restrictions,
												allergies
											)
						VALUES				(
												' . $this->db->escape($MSRegHistoryId)  . ',
												' . $this->db->escape($i+1)  . ',
												1,
												' . $this->db->escape($adultRec["firstname"])  . ',
												' . $this->db->escape($adultRec["lastname"])  . ',
												' . $this->db->escape($adultRec["gender"])  . ',
												' . $this->db->escape($adultRec["dietrest"])  . ',
												' . $this->db->escape("none")  . '
											)
					 ');
				}

				//Insert all child info
				$childInfoArr = $ms_registration_value->getChildInfo();
				for($i=0; $i<$ms_registration_value->getNumChildRegistered(); $i++)
				{
					$childRec = $childInfoArr[$i];
					if ($childRec["ischyk"] == "1")
						$persontype = 3;
					else
						$persontype = 2;
					
					$this->db->query('
						INSERT INTO			ms_reg_person
											(
												ms_reg_history_id_fk,
												ms_person_id,
												ms_person_type,
												first_name,
												last_name,
												gender,
												age,
												diet_restrictions,
												allergies
											)
						VALUES				(
												' . $this->db->escape($MSRegHistoryId)  . ',
												' . $this->db->escape($i+1)  . ',
												' . $this->db->escape($persontype)  . ',
												' . $this->db->escape($childRec["firstname"])  . ',
												' . $this->db->escape($childRec["lastname"])  . ',
												' . $this->db->escape($childRec["gender"])  . ',
												' . $this->db->escape($childRec["age"])  . ',
												' . $this->db->escape($childRec["dietrest"])  . ',
												' . $this->db->escape("none")  . '
											)
					 ');
				}

				//Insert all chyk info
				$chykInfoArr = $ms_registration_value->getCHYKInfo();
				for($i=0; $i<$ms_registration_value->getNumCHYKRegistered(); $i++)
				{
					$chykRec = $chykInfoArr[$i];
					
					$this->db->query('
						INSERT INTO			ms_reg_person
											(
												ms_reg_history_id_fk,
												ms_person_id,
												ms_person_type,
												first_name,
												last_name,
												gender,
												diet_restrictions,
												allergies
											)
						VALUES				(
												' . $this->db->escape($MSRegHistoryId)  . ',
												' . $this->db->escape($i+1)  . ',
												3,
												' . $this->db->escape($chykRec["firstname"])  . ',
												' . $this->db->escape($chykRec["lastname"])  . ',
												' . $this->db->escape($chykRec["gender"])  . ',
												' . $this->db->escape($chykRec["dietrest"])  . ',
												' . $this->db->escape("none")  . '
											)
					 ');
				}

				//Insert all biksha info
				for($i=0; $i<$ms_registration_value->getNumBiksha(); $i++)
				{
					$bikshaInfoArr = $ms_registration_value->getBikshaInfo();
					$bikshaRec = $bikshaInfoArr[$i];
					
					$this->db->query('
						INSERT INTO			ms_reg_sponsor
											(
												ms_reg_history_id_fk,
												ms_sponsor_day_id,
												ms_sponsor_day_event_id,
												ms_sponsor_type
											)
						VALUES				(
												' . $this->db->escape($MSRegHistoryId)  . ',
												' . $this->db->escape($bikshaRec["dayid"])  . ',
												' . $this->db->escape($bikshaRec["eventid"])  . ',
												1
											)
					 ');
				}

				//Insert all arathi info
				for($i=0; $i<$ms_registration_value->getNumArathi(); $i++)
				{
					$arathiInfoArr = $ms_registration_value->getArathiInfo();
					$arathiRec = $arathiInfoArr[$i];
					
					$this->db->query('
						INSERT INTO			ms_reg_sponsor
											(
												ms_reg_history_id_fk,
												ms_sponsor_day_id,
												ms_sponsor_day_event_id,
												ms_sponsor_type
											)
						VALUES				(
												' . $this->db->escape($MSRegHistoryId)  . ',
												' . $this->db->escape($arathiRec["dayid"])  . ',
												' . $this->db->escape($arathiRec["eventid"])  . ',
												2
											)
					 ');
				}
			}
			
			return $MSRegHistoryId;
		}

		public function insertMSRegistrationCheck( $ms_registration_value, $curyear)
		{
			$this->load->library('encrypt');
			
			$ms_registration_value = Mahasamadhi_registration_value::cast($ms_registration_value);
			$numtotreg = $ms_registration_value->getTotalNumRegistered();
			//$objstrhash = md5( serialize($ms_registration_value) );
			$ms_registration_value->setPaymentType("check");
			$ms_registration_value->setPaymentStatus( "2" );
			$objstrhash = $this->genMSRegistrationObjectHash($ms_registration_value);
			
			//Check for same registration already existing
			$tmp = $this->db->query('
													SELECT 		ms_reg_history_id 
													FROM 		ms_reg_history
													WHERE		obj_string_hash = ' . $this->db->escape($objstrhash) . '
												  ');

			if( $tmp->num_rows() == 1 )
			{
				return -1;
			}

			//Ensure regcode is unique			
			$numtries = 0;
			$found = true;
			while (($numtries < 10) && $found)
			{
				$regcode = $this->encrypt->get_random_password(5,5,false,false,false);
				
				$tmp = $this->db->query('
									SELECT			mrh.regcode
									FROM			ms_reg_history mrh
									WHERE			mrh.regcode = ' . $this->db->escape( $regcode ) . '
								 ');
			
				if( $tmp->num_rows() <= 0) $found = false;
				
				$numtries++;
			}
					
			if ($found)
			{
				return 0;
			}

			$curdate = date('Y-m-d H:i:s', time());

			$this->db->query('
								INSERT INTO			ms_reg_history
													(
														ms_event_id_fk,
														regcode,
														year,
														first_name,
														last_name,
														chyk_ref_first_name,
														chyk_ref_last_name,
														email,
														phone,
														address,
														address1,
														city,
														state,
														country,
														zip,
														is_teacher,
														sn_wheelchair,
														sn_room,
														sn_requests,
														numtotreg,
														numadultreg,
														numchildreg,
														numchykreg,
														numbiksha,
														numarathi,
														reg_type,
														need_accommodation,
														reg_type_desc,
														reg_case,
														reg_case_desc,
														reg_fee,
														sponsor_amount,
														donation_amount,
														discount_amount,
														payment_type,
														enabled,
														date_modified,
														date_created,
														amount_committed,
														amount_paid,
														payment_status,
														obj_string_hash
													)
								VALUES				(
														' . $this->db->escape($ms_registration_value->getEventID())  . ',
														' . $this->db->escape($regcode)  . ',
														' . $this->db->escape($curyear)  . ',
														' . $this->db->escape($ms_registration_value->getFirstName())  . ',
														' . $this->db->escape($ms_registration_value->getLastName())  . ',
														' . $this->db->escape($ms_registration_value->getCHYKRefFirstName())  . ',
														' . $this->db->escape($ms_registration_value->getCHYKRefLastName())  . ',
														' . $this->db->escape($ms_registration_value->getEmail())  . ',
														' . $this->db->escape($ms_registration_value->getPhone())  . ',
														' . $this->db->escape($ms_registration_value->getAddress())  . ',
														' . $this->db->escape($ms_registration_value->getAddress1())  . ',
														' . $this->db->escape($ms_registration_value->getCity())  . ',
														' . $this->db->escape($ms_registration_value->getState())  . ',
														' . $this->db->escape($ms_registration_value->getCountry())  . ',
														' . $this->db->escape($ms_registration_value->getZip())  . ',
														' . $this->db->escape($ms_registration_value->getIsTeacher())  . ',
														' . $this->db->escape($ms_registration_value->getSpecialNeedsWheelchair())  . ',
														' . $this->db->escape($ms_registration_value->getSpecialNeedsRoom())  . ',
														' . $this->db->escape($ms_registration_value->getSpecialRequests())  . ',
														' . $this->db->escape($numtotreg)  . ',
														' . $this->db->escape($ms_registration_value->getNumAdultRegistered())  . ',
														' . $this->db->escape($ms_registration_value->getNumChildRegistered())  . ',
														' . $this->db->escape($ms_registration_value->getNumCHYKRegistered())  . ',
														' . $this->db->escape($ms_registration_value->getNumBiksha())  . ',
														' . $this->db->escape($ms_registration_value->getNumArathi())  . ',
														' . $this->db->escape($ms_registration_value->getRegistrationType())  . ',
														' . $this->db->escape($ms_registration_value->getNeedAccommodation())  . ',
														' . $this->db->escape($ms_registration_value->getRegistrationTypeDescription())  . ',
														' . $this->db->escape($ms_registration_value->getRegistrationCase())  . ',
														' . $this->db->escape($ms_registration_value->getRegistrationCaseDescription())  . ',
														' . $this->db->escape($ms_registration_value->getRegistrationFee())  . ',
														' . $this->db->escape($ms_registration_value->getSponsorship())  . ',
														' . $this->db->escape($ms_registration_value->getDonation())  . ',
														0,
														' . $this->db->escape("check")  . ',
														1,
														STR_TO_DATE(' . $this->db->escape($curdate)  . ',' . $this->db->escape("%Y-%m-%d %T")  . '),
														STR_TO_DATE(' . $this->db->escape($curdate)  . ',' . $this->db->escape("%Y-%m-%d %T")  . '),
														' . $this->db->escape($ms_registration_value->getTotalRegistrationFee())  . ',
														0,
														2,
														' . $this->db->escape($objstrhash)  . '														
													)
							 ');
			
			$tmp = $this->db->query('
													SELECT 		ms_reg_history_id 
													FROM 		ms_reg_history
													WHERE		obj_string_hash = ' . $this->db->escape($objstrhash) . '
												  ');

			if( $tmp->num_rows() == 1 )
			{
				$MSRegHistoryId = $tmp->row()->ms_reg_history_id;
			}
			else
				$MSRegHistoryId = 0;
			
			if ($MSRegHistoryId > 0)
			{
				//Insert all adult info
				$adultInfoArr = $ms_registration_value->getAdultInfo();
				for($i=0; $i<$ms_registration_value->getNumAdultRegistered(); $i++)
				{
					$adultRec = $adultInfoArr[$i];
					
					$this->db->query('
						INSERT INTO			ms_reg_person
											(
												ms_reg_history_id_fk,
												ms_person_id,
												ms_person_type,
												first_name,
												last_name,
												gender,
												diet_restrictions,
												allergies
											)
						VALUES				(
												' . $this->db->escape($MSRegHistoryId)  . ',
												' . $this->db->escape($i+1)  . ',
												1,
												' . $this->db->escape($adultRec["firstname"])  . ',
												' . $this->db->escape($adultRec["lastname"])  . ',
												' . $this->db->escape($adultRec["gender"])  . ',
												' . $this->db->escape($adultRec["dietrest"])  . ',
												' . $this->db->escape("none")  . '
											)
					 ');
				}

				//Insert all child info
				$childInfoArr = $ms_registration_value->getChildInfo();
				for($i=0; $i<$ms_registration_value->getNumChildRegistered(); $i++)
				{
					$childRec = $childInfoArr[$i];
					if ($childRec["ischyk"] == "1")
						$persontype = 3;
					else
						$persontype = 2;
					
					$this->db->query('
						INSERT INTO			ms_reg_person
											(
												ms_reg_history_id_fk,
												ms_person_id,
												ms_person_type,
												first_name,
												last_name,
												gender,
												age,
												diet_restrictions,
												allergies
											)
						VALUES				(
												' . $this->db->escape($MSRegHistoryId)  . ',
												' . $this->db->escape($i+1)  . ',
												' . $this->db->escape($persontype)  . ',
												' . $this->db->escape($childRec["firstname"])  . ',
												' . $this->db->escape($childRec["lastname"])  . ',
												' . $this->db->escape($childRec["gender"])  . ',
												' . $this->db->escape($childRec["age"])  . ',
												' . $this->db->escape($childRec["dietrest"])  . ',
												' . $this->db->escape("none")  . '
											)
					 ');
				}

				//Insert all chyk info
				$chykInfoArr = $ms_registration_value->getCHYKInfo();
				for($i=0; $i<$ms_registration_value->getNumCHYKRegistered(); $i++)
				{
					$chykRec = $chykInfoArr[$i];
					
					$this->db->query('
						INSERT INTO			ms_reg_person
											(
												ms_reg_history_id_fk,
												ms_person_id,
												ms_person_type,
												first_name,
												last_name,
												gender,
												diet_restrictions,
												allergies
											)
						VALUES				(
												' . $this->db->escape($MSRegHistoryId)  . ',
												' . $this->db->escape($i+1)  . ',
												3,
												' . $this->db->escape($chykRec["firstname"])  . ',
												' . $this->db->escape($chykRec["lastname"])  . ',
												' . $this->db->escape($chykRec["gender"])  . ',
												' . $this->db->escape($chykRec["dietrest"])  . ',
												' . $this->db->escape("none")  . '
											)
					 ');
				}

				//Insert all biksha info
				for($i=0; $i<$ms_registration_value->getNumBiksha(); $i++)
				{
					$bikshaInfoArr = $ms_registration_value->getBikshaInfo();
					$bikshaRec = $bikshaInfoArr[$i];
					
					$this->db->query('
						INSERT INTO			ms_reg_sponsor
											(
												ms_reg_history_id_fk,
												ms_sponsor_day_id,
												ms_sponsor_day_event_id,
												ms_sponsor_type
											)
						VALUES				(
												' . $this->db->escape($MSRegHistoryId)  . ',
												' . $this->db->escape($bikshaRec["dayid"])  . ',
												' . $this->db->escape($bikshaRec["eventid"])  . ',
												1
											)
					 ');
				}

				//Insert all arathi info
				for($i=0; $i<$ms_registration_value->getNumArathi(); $i++)
				{
					$arathiInfoArr = $ms_registration_value->getArathiInfo();
					$arathiRec = $arathiInfoArr[$i];
					
					$this->db->query('
						INSERT INTO			ms_reg_sponsor
											(
												ms_reg_history_id_fk,
												ms_sponsor_day_id,
												ms_sponsor_day_event_id,
												ms_sponsor_type
											)
						VALUES				(
												' . $this->db->escape($MSRegHistoryId)  . ',
												' . $this->db->escape($arathiRec["dayid"])  . ',
												' . $this->db->escape($arathiRec["eventid"])  . ',
												2
											)
					 ');
				}
			}
			
			return $MSRegHistoryId;			
		}

		public function updateMahasamadhiRegistration( $ms_registration_value, $ms_compare_array )
		{
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
			$this->load->model('values/mahasamadhi/Mahasamadhi_registration_value');
			
			$curyear = $this->Walk_proxy->getCurrentYear();
			$ms_registration_value = Mahasamadhi_registration_value::cast($ms_registration_value);
			$objstrhash = $this->genMSRegistrationObjectHash($ms_registration_value);
			
			//Set dependent field values
			$numtotreg = $ms_registration_value->getTotalNumRegistered();

			$curdate = date('Y-m-d H:i:s', time());

			//If any elements of ms_reg_history changed do an update
			if ($ms_compare_array['mrh'] != 1)
			{
				$tmp = $this->db->query('
					UPDATE	ms_reg_history
					SET		first_name = ' . $this->db->escape($ms_registration_value->getFirstName()) . ',
							last_name = ' . $this->db->escape($ms_registration_value->getLastName()) . ',
							chyk_ref_first_name = ' . $this->db->escape($ms_registration_value->getCHYKRefFirstName()) . ',
							chyk_ref_last_name = ' . $this->db->escape($ms_registration_value->getCHYKRefLastName()) . ',
							email = ' . $this->db->escape($ms_registration_value->getEmail()) . ',
							phone = ' . $this->db->escape($ms_registration_value->getPhone()) . ',
							address = ' . $this->db->escape($ms_registration_value->getAddress()) . ',
							address1 = ' . $this->db->escape($ms_registration_value->getAddress1()) . ',
							city = ' . $this->db->escape($ms_registration_value->getCity()) . ',
							state = ' . $this->db->escape($ms_registration_value->getState()) . ',
							country = ' . $this->db->escape($ms_registration_value->getCountry()) . ',
							zip = ' . $this->db->escape($ms_registration_value->getZip()) . ',
							is_teacher = ' . $this->db->escape($ms_registration_value->getIsTeacher()) . ',
							sn_wheelchair = ' . $this->db->escape($ms_registration_value->getSpecialNeedsWheelchair()) . ',
							sn_room = ' . $this->db->escape($ms_registration_value->getSpecialNeedsRoom()) . ',
							sn_requests = ' . $this->db->escape($ms_registration_value->getSpecialRequests()) . ',
							numtotreg = ' . $this->db->escape($numtotreg) . ',
							numadultreg = ' . $this->db->escape($ms_registration_value->getNumAdultRegistered()) . ',
							numchildreg = ' . $this->db->escape($ms_registration_value->getNumChildRegistered()) . ',
							numchykreg = ' . $this->db->escape($ms_registration_value->getNumCHYKRegistered()) . ',
							numbiksha = ' . $this->db->escape($ms_registration_value->getNumBiksha()) . ',
							numarathi = ' . $this->db->escape($ms_registration_value->getNumArathi()) . ',
							reg_case_desc = ' . $this->db->escape($ms_registration_value->getRegistrationCaseDescription()) . ',
							reg_case = ' . $this->db->escape($ms_registration_value->getRegistrationCase()) . ',
							reg_type_desc = ' . $this->db->escape($ms_registration_value->getRegistrationTypeDescription()) . ',
							need_accommodation = ' . $this->db->escape($ms_registration_value->getNeedAccommodation()) . ',
							reg_type = ' . $this->db->escape($ms_registration_value->getRegistrationType()) . ',
							reg_fee = ' . $this->db->escape($ms_registration_value->getRegistrationFee()) . ',
							payment_type = ' . $this->db->escape($ms_registration_value->getPaymentType()) . ',
							payment_transaction_id = ' . $this->db->escape($ms_registration_value->getPaymentTransactionID()) . ',
							payment_status = ' . $this->db->escape($ms_registration_value->getPaymentStatus()) . ',
							check_num = ' . $this->db->escape($ms_registration_value->getCheckNum()) . ',
							sponsor_amount = ' . $this->db->escape($ms_registration_value->getSponsorship()) . ',
							donation_amount = ' . $this->db->escape($ms_registration_value->getDonation()) . ',
							discount_amount = ' . $this->db->escape($ms_registration_value->getGeneralDiscount()) . ',
							amount_committed = ' . $this->db->escape($ms_registration_value->getAmountCommitted()) . ',
							amount_paid = ' . $this->db->escape($ms_registration_value->getAmountPaid()) . ',
							comments = ' . $this->db->escape($ms_registration_value->getComments()) . ',
							enabled = ' . $this->db->escape($ms_registration_value->getEnabled()) . ',
							date_modified = STR_TO_DATE(' . $this->db->escape($curdate)  . ',' . $this->db->escape("%Y-%m-%d %T")  . '),
							obj_string_hash = ' . $this->db->escape( $objstrhash ) . '
					WHERE	ms_reg_history_id = ' . $this->db->escape($ms_registration_value->getMSRegHistoryID()) . '
				 ');
			}
			
			//If any elements of ms_reg_person changed do a delete->insert
			if ($ms_compare_array['mrp'] != 1)
			{
				//Delete existing adult info
				$this->db->query('
					DELETE FROM	ms_reg_person
					WHERE		ms_reg_history_id_fk = ' . $this->db->escape($ms_registration_value->getMSRegHistoryID()) . '
					AND			ms_person_type = 1
				 ');
				
				//Insert all adult info
				$adultInfoArr = $ms_registration_value->getAdultInfo();
				for($i=0; $i<$ms_registration_value->getNumAdultRegistered(); $i++)
				{
					$adultRec = $adultInfoArr[$i];
					
					$this->db->query('
						INSERT INTO			ms_reg_person
											(
												ms_reg_history_id_fk,
												ms_person_id,
												ms_person_type,
												first_name,
												last_name,
												gender,
												diet_restrictions,
												allergies
											)
						VALUES				(
												' . $this->db->escape($ms_registration_value->getMSRegHistoryID()) . ',
												' . $this->db->escape($i+1)  . ',
												1,
												' . $this->db->escape($adultRec["firstname"])  . ',
												' . $this->db->escape($adultRec["lastname"])  . ',
												' . $this->db->escape($adultRec["gender"])  . ',
												' . $this->db->escape($adultRec["dietrest"])  . ',
												' . $this->db->escape("none")  . '
											)
					 ');
				}

				//Delete existing child info
				$this->db->query('
					DELETE FROM	ms_reg_person
					WHERE		ms_reg_history_id_fk = ' . $this->db->escape($ms_registration_value->getMSRegHistoryID()) . '
					AND			ms_person_type = 2
				 ');
				
				//Insert all child info
				$childInfoArr = $ms_registration_value->getChildInfo();
				for($i=0; $i<$ms_registration_value->getNumChildRegistered(); $i++)
				{
					$childRec = $childInfoArr[$i];
					if ($childRec["ischyk"] == "1")
						$persontype = 3;
					else
						$persontype = 2;
					
					$this->db->query('
						INSERT INTO			ms_reg_person
											(
												ms_reg_history_id_fk,
												ms_person_id,
												ms_person_type,
												first_name,
												last_name,
												gender,
												age,
												diet_restrictions,
												allergies
											)
						VALUES				(
												' . $this->db->escape($ms_registration_value->getMSRegHistoryID()) . ',
												' . $this->db->escape($i+1)  . ',
												' . $this->db->escape($persontype)  . ',
												' . $this->db->escape($childRec["firstname"])  . ',
												' . $this->db->escape($childRec["lastname"])  . ',
												' . $this->db->escape($childRec["gender"])  . ',
												' . $this->db->escape($childRec["age"])  . ',
												' . $this->db->escape($childRec["dietrest"])  . ',
												' . $this->db->escape("none")  . '
											)
					 ');
				}

				//Delete existing CHYK info
				$this->db->query('
					DELETE FROM	ms_reg_person
					WHERE		ms_reg_history_id_fk = ' . $this->db->escape($ms_registration_value->getMSRegHistoryID()) . '
					AND			ms_person_type = 3
				 ');
				
				//Insert all chyk info
				$chykInfoArr = $ms_registration_value->getCHYKInfo();
				for($i=0; $i<$ms_registration_value->getNumCHYKRegistered(); $i++)
				{
					$chykRec = $chykInfoArr[$i];
					
					$this->db->query('
						INSERT INTO			ms_reg_person
											(
												ms_reg_history_id_fk,
												ms_person_id,
												ms_person_type,
												first_name,
												last_name,
												gender,
												diet_restrictions,
												allergies
											)
						VALUES				(
												' . $this->db->escape($ms_registration_value->getMSRegHistoryID()) . ',
												' . $this->db->escape($i+1)  . ',
												3,
												' . $this->db->escape($chykRec["firstname"])  . ',
												' . $this->db->escape($chykRec["lastname"])  . ',
												' . $this->db->escape($chykRec["gender"])  . ',
												' . $this->db->escape($chykRec["dietrest"])  . ',
												' . $this->db->escape("none")  . '
											)
					 ');
				}
			}
			
			//If any elements of ms_reg_sponsor changed do a delete->insert
			if ($ms_compare_array['mrs'] != 1)
			{
				//Delete existing biksha info
				$this->db->query('
					DELETE FROM	ms_reg_sponsor
					WHERE		ms_reg_history_id_fk = ' . $this->db->escape($ms_registration_value->getMSRegHistoryID()) . '
					AND			ms_sponsor_type = 1
				 ');
				
				//Insert all biksha info
				for($i=0; $i<$ms_registration_value->getNumBiksha(); $i++)
				{
					$bikshaInfoArr = $ms_registration_value->getBikshaInfo();
					$bikshaRec = $bikshaInfoArr[$i];
					
					$this->db->query('
						INSERT INTO			ms_reg_sponsor
											(
												ms_reg_history_id_fk,
												ms_sponsor_day_id,
												ms_sponsor_day_event_id,
												ms_sponsor_type
											)
						VALUES				(
												' . $this->db->escape($ms_registration_value->getMSRegHistoryID()) . ',
												' . $this->db->escape($bikshaRec["dayid"])  . ',
												' . $this->db->escape($bikshaRec["eventid"])  . ',
												1
											)
					 ');
				}

				//Delete existing arathi info
				$this->db->query('
					DELETE FROM	ms_reg_sponsor
					WHERE		ms_reg_history_id_fk = ' . $this->db->escape($ms_registration_value->getMSRegHistoryID()) . '
					AND			ms_sponsor_type = 2
				 ');
				
				//Insert all arathi info
				for($i=0; $i<$ms_registration_value->getNumArathi(); $i++)
				{
					$arathiInfoArr = $ms_registration_value->getArathiInfo();
					$arathiRec = $arathiInfoArr[$i];
					
					$this->db->query('
						INSERT INTO			ms_reg_sponsor
											(
												ms_reg_history_id_fk,
												ms_sponsor_day_id,
												ms_sponsor_day_event_id,
												ms_sponsor_type
											)
						VALUES				(
												' . $this->db->escape($ms_registration_value->getMSRegHistoryID()) . ',
												' . $this->db->escape($arathiRec["dayid"])  . ',
												' . $this->db->escape($arathiRec["eventid"])  . ',
												2
											)
					 ');
				}
			}
			
			return $ms_registration_value->getMSRegHistoryID();
		}

		//Update registration hash
		public function updateMSRegistrationObjectHash( $MSRegHistoryId, $regobjhash )
		{
			
			$this->db->query('
								UPDATE			ms_reg_history
								SET				obj_string_hash = ' . $this->db->escape($regobjhash) . '
								WHERE			ms_reg_history_id = ' . $MSRegHistoryId  . '
							 ');
							 
			return $MSRegHistoryId;
		}

		//Check if person already registered for event 
		public function isEventRegistered( $eventID, $firstname, $lastname, $email_contact )
		{
			
			$tmp = $this->db->query('
								SELECT			msrh.ms_reg_history_id
								FROM			ms_reg_history msrh
								WHERE			msrh.first_name = ' . $this->db->escape($firstname) . '
								AND				msrh.last_name = ' . $this->db->escape($lastname) . '
								AND				msrh.email = ' . $this->db->escape($email_contact) . '
								AND				msrh.ms_event_id_fk = ' . $this->db->escape($eventID) . '
								AND				msrh.enabled = 1
							 ');
							 
			if( $tmp->num_rows() > 0)
				return TRUE;
			else
				return FALSE;
		}

		public function getEventUnpaidCheckInfo( $curyear )
		{
			
			$unpaidchecklist = $this->db->query('
												SELECT    	msrh.ms_reg_history_id,
															msrh.regcode,
															msrh.first_name,
												          	msrh.last_name,
															msrh.email,
															msrh.numtotreg,
															msrh.amount_committed,
															mse.description,
															msrh.phone,
															msrh.address,
															msrh.city,
															msrh.state,
															msrh.zip,
															msrh.country,
															msrh.reg_type_desc,
															msrh.reg_case_desc,
															numadultreg,
															numchildreg,
															numchykreg
												FROM      	ms_reg_history msrh
															INNER JOIN ms_event mse ON mse.ms_event_id=msrh.ms_event_id_fk
												WHERE       msrh.payment_status <> 1
												AND			msrh.payment_type = ' . $this->db->escape( 'check' ) . '
												AND			msrh.year = ' . $this->db->escape( $curyear ) . '
												AND			msrh.enabled = 1
											  ');

			
			$regInfo = array();
			if( $unpaidchecklist->num_rows() > 0)
			{
				foreach ($unpaidchecklist->result() as $regIdRow)
				{
					$checkInfo = array();		
					array_push($checkInfo, $regIdRow->ms_reg_history_id);					
					array_push($checkInfo, $regIdRow->first_name);					
					array_push($checkInfo, $regIdRow->last_name);					
					array_push($checkInfo, $regIdRow->email);					
					array_push($checkInfo, $regIdRow->numtotreg);					
					array_push($checkInfo, $regIdRow->amount_committed);					
					array_push($checkInfo, $regIdRow->description);					
					array_push($checkInfo, $regIdRow->phone);					
					array_push($checkInfo, $regIdRow->address);					
					array_push($checkInfo, $regIdRow->city);					
					array_push($checkInfo, $regIdRow->state);					
					array_push($checkInfo, $regIdRow->zip);	
					array_push($checkInfo, $regIdRow->country);
					array_push($checkInfo, $regIdRow->reg_case_desc);	
					array_push($checkInfo, $regIdRow->numadultreg);		//(14)	
					array_push($checkInfo, $regIdRow->numchildreg);			
					array_push($checkInfo, $regIdRow->numchykreg);
					array_push($checkInfo, $regIdRow->regcode);		//(17)	
					array_push($checkInfo, $regIdRow->reg_type_desc);	//(18)	
					
					array_push($regInfo, $checkInfo);					
				}
			}
				
			return $regInfo;
		}

		public function getEventUnpaidCheckRegId( $curyear )
		{
			
			$unpaidchecklist = $this->db->query('
												SELECT    	msrh.ms_reg_history_id
												FROM      	ms_reg_history msrh
												WHERE       msrh.payment_status <> 1
												AND			msrh.payment_type = ' . $this->db->escape( 'check' ) . '
												AND			msrh.year = ' . $this->db->escape( $curyear ) . '
												AND			msrh.enabled = 1
											  ');
			
			$regId = array();
			if( $unpaidchecklist->num_rows() > 0)
			{
				foreach ($unpaidchecklist->result() as $regIdRow)
				{
					array_push($regId, $regIdRow->ms_reg_history_id);					
				}
			}
				
			return $regId;
		}

		public function completeMSRegistrationCheck( $MSRegHistoryId, $checknum, $checkamount )
		{
			
			$ms_registration_value = $this->getRegistrantDetailInfo( $MSRegHistoryId );
			$ms_registration_value->setAmountPaid($checkamount);
			$ms_registration_value->setCheckNum($checknum);
			$regobjhash = $this->genMSRegistrationObjectHash( $ms_registration_value );
			
			$this->db->query('
								UPDATE			ms_reg_history
								SET				payment_status = 1,
												check_num = ' . $this->db->escape($checknum) . ',
												amount_paid = ' . $this->db->escape($checkamount) . ',
												obj_string_hash = ' . $this->db->escape( $regobjhash ) . ',
												date_modified = Now()
								WHERE			ms_reg_history_id = ' . $MSRegHistoryId  . '
								AND				payment_type = ' . $this->db->escape('check') . '			
							 ');
							 
			return $MSRegHistoryId;
		}

		public function getRegIDFromRegCode( $ms_reg_code  )
		{
			
			$tmp = $this->db->query('
								SELECT			mrh.ms_reg_history_id
								FROM			ms_reg_history mrh
								WHERE			mrh.regcode = ' . $this->db->escape($ms_reg_code) . '
							 ');
							 
			if ($tmp->num_rows() > 0)
				return $tmp->row()->ms_reg_history_id;
			else
				return 0;
		}

		public function getRegCodeFromRegID( $ms_reg_history_id  )
		{
			
			$tmp = $this->db->query('
								SELECT			mrh.regcode
								FROM			ms_reg_history mrh
								WHERE			mrh.ms_reg_history_id = ' . $this->db->escape($ms_reg_history_id) . '
							 ');
							 
			if ($tmp->num_rows() > 0)
				return $tmp->row()->regcode;
			else
				return 0;
		}

		//Get detailed registrant value object
		public function getRegistrantDetailInfo( $MSRegHistoryId )
		{
			$this->load->model('values/mahasamadhi/Mahasamadhi_registration_value');			
			
			//Get registration summary
			$reglist = $this->db->query('
												SELECT    	msrh.ms_reg_history_id,
															msrh.regcode,
															msrh.year,
															msrh.first_name,
												          	msrh.last_name,
															msrh.chyk_ref_first_name,
															msrh.chyk_ref_last_name,
															msrh.email,
															msrh.phone,
															msrh.address,
															msrh.address1,
															msrh.city,
															msrh.state,
															msrh.country,
															msrh.zip,
															msrh.is_teacher,
															msrh.sn_wheelchair,
															msrh.sn_room,
															msrh.sn_requests,
															msrh.numadultreg,
															msrh.numchildreg,
															msrh.numchykreg,
															msrh.numbiksha,
															msrh.numarathi,
															msrh.payment_type,
															msrh.check_num,
															msrh.payment_transaction_id,
															msrh.payment_status,
															msrh.need_accommodation,
															msrh.reg_type,
															msrh.reg_type_desc,
															msrh.reg_case,
															msrh.reg_case_desc,
															msrh.reg_fee,
															msrh.sponsor_amount,
															msrh.donation_amount,
															msrh.discount_amount,
															msrh.amount_committed,
															msrh.amount_paid,
															msrh.ms_event_id_fk,
															msrh.comments,
															msrh.date_created,
															msrh.date_modified
												FROM      	ms_reg_history msrh
												WHERE       msrh.ms_reg_history_id = ' . $this->db->escape( $MSRegHistoryId ) . '
											  ');

			
			$ms_registration_value = new Mahasamadhi_registration_value();
			if( $reglist->num_rows() > 0)
			{
				foreach ($reglist->result() as $regIdRow)
				{		
					$ms_registration_value->setMSRegHistoryID($regIdRow->ms_reg_history_id);
					$ms_registration_value->setEventID($regIdRow->ms_event_id_fk);
					$ms_registration_value->setRegCode($regIdRow->regcode);
					$ms_registration_value->setCurrentYear($regIdRow->year);
					$ms_registration_value->setFirstName($regIdRow->first_name);
					$ms_registration_value->setLastName($regIdRow->last_name);
					$ms_registration_value->setCHYKRefFirstName($regIdRow->chyk_ref_first_name);
					$ms_registration_value->setCHYKRefLastName($regIdRow->chyk_ref_last_name);
					$ms_registration_value->setEmail($regIdRow->email);
					$ms_registration_value->setPhone($regIdRow->phone);
					$ms_registration_value->setAddress($regIdRow->address);
					$ms_registration_value->setAddress1($regIdRow->address1);
					$ms_registration_value->setCity($regIdRow->city);
					$ms_registration_value->setState($regIdRow->state);
					$ms_registration_value->setCountry($regIdRow->country);
					$ms_registration_value->setZip($regIdRow->zip);
					$ms_registration_value->setIsTeacher($regIdRow->is_teacher);
					$ms_registration_value->setSpecialNeedsWheelchair($regIdRow->sn_wheelchair);
					$ms_registration_value->setSpecialNeedsRoom($regIdRow->sn_room);
					$ms_registration_value->setSpecialRequests($regIdRow->sn_requests);
					$ms_registration_value->setNumAdultRegistered($regIdRow->numadultreg);
					$ms_registration_value->setNumChildRegistered($regIdRow->numchildreg);
					$ms_registration_value->setNumCHYKRegistered($regIdRow->numchykreg);
					$ms_registration_value->setNumBiksha($regIdRow->numbiksha);
					$ms_registration_value->setNumArathi($regIdRow->numarathi);
					$ms_registration_value->setRegistrationTypeDescription( $regIdRow->reg_type_desc );
					$ms_registration_value->setRegistrationType( $regIdRow->reg_type );
					$ms_registration_value->setNeedAccommodation( $regIdRow->need_accommodation );
					$ms_registration_value->setRegistrationCaseDescription( $regIdRow->reg_case_desc );
					$ms_registration_value->setRegistrationCase( $regIdRow->reg_case );
					$ms_registration_value->setAmountCommitted( $regIdRow->amount_committed );
					$ms_registration_value->setAmountPaid( $regIdRow->amount_paid );
					$ms_registration_value->setRegistrationFee( $regIdRow->reg_fee );
					$ms_registration_value->setSponsorship( $regIdRow->sponsor_amount );
					$ms_registration_value->setDonation( $regIdRow->donation_amount );
					$ms_registration_value->setGeneralDiscount( $regIdRow->discount_amount );
					$ms_registration_value->setPaymentType( $regIdRow->payment_type );
					$ms_registration_value->setCheckNum( $regIdRow->check_num );
					$ms_registration_value->setPaymentTransactionID( $regIdRow->payment_transaction_id );
					$ms_registration_value->setPaymentStatus( $regIdRow->payment_status );
                    $ms_registration_value->setComments( $regIdRow->comments );
					$ms_registration_value->setDateCreated( $regIdRow->date_created );
                    $ms_registration_value->setDateModified( $regIdRow->date_modified );
				}
			}
				
			//Get adult detail for registration
			$adultInfoArr = array();
			$personlist = $this->db->query('
												SELECT    	mrp.ms_person_id,
															mrp.first_name,
												          	mrp.last_name,
															mrp.gender,
															mrp.diet_restrictions,
															mrp.allergies
												FROM      	ms_reg_person mrp
												WHERE       mrp.ms_reg_history_id_fk = ' . $this->db->escape( $MSRegHistoryId ) . '
												AND			mrp.ms_person_type = 1
												AND			mrp.enabled = 1
											  ');

			
			if( $personlist->num_rows() > 0)
			{
				foreach ($personlist->result() as $personRow)
				{		
					$adultRec = array();
					$adultRec['firstname'] = $personRow->first_name;
					$adultRec['lastname'] = $personRow->last_name;
					$adultRec['gender'] = $personRow->gender;
					$adultRec['dietrest'] = $personRow->diet_restrictions;
					$adultRec['allergies'] = $personRow->allergies;
					
					array_push($adultInfoArr, $adultRec);
				}
			}
			$ms_registration_value->setAdultInfo( $adultInfoArr );

			//Get child detail for registration
			$childInfoArr = array();
			$personlist = $this->db->query('
												SELECT    	mrp.ms_person_id,
															mrp.ms_person_type,
															mrp.first_name,
												          	mrp.last_name,
															mrp.gender,
															mrp.age,
															mrp.diet_restrictions,
															mrp.allergies
												FROM      	ms_reg_person mrp
												WHERE       mrp.ms_reg_history_id_fk = ' . $this->db->escape( $MSRegHistoryId ) . '
												AND			mrp.ms_person_type = 2
												AND			mrp.enabled = 1
											  ');

			
			if( $personlist->num_rows() > 0)
			{
				foreach ($personlist->result() as $personRow)
				{		
					$childRec = array();
					$childRec['type'] = $personRow->ms_person_type;
					$childRec['firstname'] = $personRow->first_name;
					$childRec['lastname'] = $personRow->last_name;
					$childRec['gender'] = $personRow->gender;
					$childRec['age'] = $personRow->age;
					$childRec['dietrest'] = $personRow->diet_restrictions;
					$childRec['allergies'] = $personRow->allergies;
					
					array_push($childInfoArr, $childRec);
				}
			}
			$ms_registration_value->setChildInfo( $childInfoArr );

			//Get CHYK detail for registration
			$chykInfoArr = array();
			$personlist = $this->db->query('
												SELECT    	mrp.ms_person_id,
															mrp.first_name,
												          	mrp.last_name,
															mrp.gender,
															mrp.diet_restrictions,
															mrp.allergies
												FROM      	ms_reg_person mrp
												WHERE       mrp.ms_reg_history_id_fk = ' . $this->db->escape( $MSRegHistoryId ) . '
												AND			mrp.ms_person_type = 3
												AND			mrp.enabled = 1
											  ');

			
			if( $personlist->num_rows() > 0)
			{
				foreach ($personlist->result() as $personRow)
				{		
					$chykRec = array();
					$chykRec['firstname'] = $personRow->first_name;
					$chykRec['lastname'] = $personRow->last_name;
					$chykRec['gender'] = $personRow->gender;
					$chykRec['dietrest'] = $personRow->diet_restrictions;
					$chykRec['allergies'] = $personRow->allergies;
					
					array_push($chykInfoArr, $chykRec);
				}
			}
			$ms_registration_value->setCHYKInfo( $chykInfoArr );

			//Get bhiksha detail for registration
			$bhiksaInfoArr = array();
			$sponsorlist = $this->db->query('
												SELECT    	mrs.ms_sponsor_day_id,
															mrs.ms_sponsor_day_event_id
												FROM      	ms_reg_sponsor mrs
												WHERE       mrs.ms_reg_history_id_fk = ' . $this->db->escape( $MSRegHistoryId ) . '
												AND			mrs.ms_sponsor_type = 1
												AND			mrs.enabled = 1
											  ');

			
			if( $sponsorlist->num_rows() > 0)
			{
				foreach ($sponsorlist->result() as $sponsorRow)
				{		
					$bhikshaRec = array();
					$bhikshaRec['dayid'] = $sponsorRow->ms_sponsor_day_id;
					$bhikshaRec['eventid'] = $sponsorRow->ms_sponsor_day_event_id;
					
					array_push($bhiksaInfoArr, $bhikshaRec);
				}
			}
			$ms_registration_value->setBikshaInfo( $bhiksaInfoArr );
			
			//Get arathi detail for registration
			$arathiInfoArr = array();
			$sponsorlist = $this->db->query('
												SELECT    	mrs.ms_sponsor_day_id,
															mrs.ms_sponsor_day_event_id
												FROM      	ms_reg_sponsor mrs
												WHERE       mrs.ms_reg_history_id_fk = ' . $this->db->escape( $MSRegHistoryId ) . '
												AND			mrs.ms_sponsor_type = 2
												AND			mrs.enabled = 1
											  ');

			
			if( $sponsorlist->num_rows() > 0)
			{
				foreach ($sponsorlist->result() as $sponsorRow)
				{		
					$arathiRec = array();
					$arathiRec['dayid'] = $sponsorRow->ms_sponsor_day_id;
					$arathiRec['eventid'] = $sponsorRow->ms_sponsor_day_event_id;
					
					array_push($arathiInfoArr, $arathiRec);
				}
			}
			$ms_registration_value->setArathiInfo( $arathiInfoArr );

			return $ms_registration_value;
		}

		//Get all registrations id's
		public function getAllMSRegID( $curyear )
		{
			
			$tmp = $this->db->query('
												SELECT    	msrh.ms_reg_history_id
												FROM      	ms_reg_history msrh
												WHERE       msrh.year = ' . $this->db->escape( $curyear ) . '
											  ');
			
			$msregidarr = array();
			if( $tmp->num_rows() > 0)
			{
				foreach ($tmp->result() as $regIdRow)
				{
					array_push($msregidarr, $regIdRow->ms_reg_history_id);					
				}
			}
				
			return $msregidarr;
		}

		//Get all persons registered for mahasamadhi registrations
		public function getAllMahasamadhiRegistrations( $curyear )
		{
			$this->load->model('proxies/mahasamadhi/Mahasamadhi_proxy');
			$this->load->model('values/mahasamadhi/Mahasamadhi_registration_value');

			$msreglist = $this->db->query('
						SELECT 	msrh.ms_reg_history_id,
								msrh.regcode,
								msrh.first_name,
								msrh.last_name,
								msrh.chyk_ref_first_name,
								msrh.chyk_ref_last_name,
								msrh.email,
								msrh.phone,
								msrh.address,
								msrh.address1,
								msrh.city,
								msrh.state,
								msrh.zip,
								msrh.is_teacher,
								msrh.sn_wheelchair,
								msrh.sn_room,
								msrh.sn_requests,
								msrh.country,
								msrh.numadultreg,
								msrh.numchildreg,
								msrh.numchykreg,
								msrh.reg_type,
								msrh.need_accommodation,
								msrh.reg_type_desc,
								msrh.reg_case,
								msrh.reg_case_desc,
								msrh.reg_fee,
								msrh.payment_type,
								msrh.payment_transaction_id,
								msrh.payment_status,
								msrh.check_num,
								msrh.sponsor_amount,
								msrh.donation_amount,
								msrh.discount_amount,
								msrh.comments
						FROM ms_reg_history msrh
						WHERE msrh.enabled = 1
						AND msrh.year =  ' . $this->db->escape( $curyear ) . '
						ORDER BY msrh.ms_reg_history_id DESC;
					');
								
			$regInfo = array();
			if( $msreglist->num_rows() > 0)
			{
				foreach ($msreglist->result() as $regRow)
				{
					$ms_registration_value = new Mahasamadhi_registration_value();
					
					$ms_registration_value->setCurrentYear( $curyear );
					$ms_registration_value->setMSRegHistoryID( $regRow->ms_reg_history_id );
					$ms_registration_value->setRegCode( $regRow->regcode );	
					$ms_registration_value->setFirstName( $regRow->first_name );
					$ms_registration_value->setLastName( $regRow->last_name );
					$ms_registration_value->setCHYKRefFirstName($regRow->chyk_ref_first_name);
					$ms_registration_value->setCHYKRefLastName($regRow->chyk_ref_last_name);
					$ms_registration_value->setEmail( $regRow->email );
					$ms_registration_value->setPhone( $regRow->phone );
					$ms_registration_value->setAddress( $regRow->address );
					$ms_registration_value->setAddress1( $regRow->address );
					$ms_registration_value->setCity( $regRow->city );
					$ms_registration_value->setState( $regRow->state );
					$ms_registration_value->setZip( $regRow->zip );
					$ms_registration_value->setIsTeacher($regRow->is_teacher);
					$ms_registration_value->setSpecialNeedsWheelchair($regRow->sn_wheelchair);
					$ms_registration_value->setSpecialNeedsRoom($regRow->sn_room);
					$ms_registration_value->setSpecialRequests($regRow->sn_requests);
					$ms_registration_value->setCountry($regRow->country);
					$ms_registration_value->setNumAdultRegistered( $regRow->numadultreg );
					$ms_registration_value->setNumChildRegistered( $regRow->numchildreg );
					$ms_registration_value->setNumCHYKRegistered( $regRow->numchykreg );
					$ms_registration_value->setRegistrationTypeDescription( $regRow->reg_type_desc );
					$ms_registration_value->setRegistrationType( $regRow->reg_type );
					$ms_registration_value->setNeedAccommodation( $regRow->need_accommodation );
					$ms_registration_value->setRegistrationCase( $regRow->reg_case );
					$ms_registration_value->setRegistrationCaseDescription( $regRow->reg_case_desc );
					$ms_registration_value->setRegistrationFee( $regRow->reg_fee );					
					$ms_registration_value->setPaymentType( $regRow->payment_type );
					$ms_registration_value->setPaymentTransactionID( $regRow->payment_transaction_id );
					$ms_registration_value->setPaymentStatus( $regRow->payment_status );
					$ms_registration_value->setCheckNum( $regRow->check_num );					
					$ms_registration_value->setSponsorship( $regRow->sponsor_amount );
					$ms_registration_value->setDonation( $regRow->donation_amount );
					$ms_registration_value->setGeneralDiscount( $regRow->discount_amount );
					$ms_registration_value->setComments( $regRow->comments );
										
					array_push($regInfo, $ms_registration_value);
				}
			}
				
			return $regInfo;
		}

		//Payment verification through Paypal failed.
		public function sendEventRegistrationFailedEmailPaypal( $ms_registration_value, $desc, $curyear, $paypal_response )
		{
			$this->load->library('encrypt');

			$ms_registration_value = Mahasamadhi_registration_value::cast($ms_registration_value);
			$desc = $this->getEventName( 1 );
			
			$message = '';
			$message .= '<p><b>Your  ' . $curyear . ' ' . $desc.'</b></p>';
			$message .= '<p>Hari OM ' . $ms_registration_value->getFirstName() . 'ji,</p>';
			$message .= '<p>Your Paypal/Credit Card Payment Request failed</p>';
			$message .= '<p>Your Registration for ' . $desc . ' ' . $curyear . ' is <u><b>NOT</b></u> confirmed:</p>';
			$message .= '<p>';
			$message .= '<table border="0">';
			$message .= '<tr><td width="250">Registration Code:</td><td><b>' . $ms_registration_value->getRegCode() . '</b></td></tr>';
			$message .= '<tr><td width="250">Registration Type:</td><td>' . $ms_registration_value->getRegistrationTypeDescription() . '</td></tr>';
			$message .= '<tr><td width="250">Occupancy:</td><td>' . $ms_registration_value->getRegistrationCaseDescription() . '</td></tr>';
			$message .= '<tr><td width="250">Primary Contact Name:</td><td>' . $ms_registration_value->getFirstName() . ' ' . $ms_registration_value->getLastName() . '</td></tr>';
			$message .= '<tr><td width="250">Email:</td><td>' . $ms_registration_value->getEmail() . '</td></tr>';
			$message .= '<tr><td width="250">Phone:</td><td>' . $ms_registration_value->getPhone() . '</td></tr>';
			$message .= '<tr><td width="250">Address1:</td><td>' . $ms_registration_value->getAddress() . '</td></tr>';
			$message .= '<tr><td width="250">Address2:</td><td>' . $ms_registration_value->getAddress1() . '</td></tr>';
			$message .= '<tr><td width="250">City:</td><td>' . $ms_registration_value->getCity() . '</td></tr>';
			$message .= '<tr><td width="250">State/Province:</td><td>' . $ms_registration_value->getState() . '</td></tr>';
			$message .= '<tr><td width="250">Country:</td><td>' . $ms_registration_value->getCountry() . '</td></tr>';
			$message .= '<tr><td width="250">Postal Code:</td><td>' . $ms_registration_value->getZip() . '</td></tr>';

			$needacc = $ms_registration_value->getNeedAccommodation();
			if ($needacc == 0)
			{
				$message .= '<tr><td width="250">Accommodation Not Required</td><td></td></tr>';
			}

			$numAdult = $ms_registration_value->getNumAdultRegistered();
			if ($numAdult > 0)
			{
				$message .= '<tr><td width="250">#Adult Attendees:</td><td>' . $numAdult . '</td></tr>';
				for($i=0; $i<$numAdult; $i++)
				{
					$adultInfoArr = $ms_registration_value->getAdultInfo();
					$adultRec = $adultInfoArr[$i];
		
					//$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$adultRec["firstname"].' '.$adultRec["lastname"].','.$adultRec["gender"].','.$adultRec["dietrest"].','.$adultRec["allergies"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$adultRec["firstname"].' '.$adultRec["lastname"].','.$adultRec["gender"].','.$adultRec["dietrest"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
			}
			
			$numChild = $ms_registration_value->getNumChildRegistered();
			if ($numChild > 0)
			{
				$message .= '<tr><td width="250">#Child Attendees:</td><td>' . $numChild . '</td></tr>';
				for($i=0; $i<$numChild; $i++)
				{
					$childInfoArr = $ms_registration_value->getChildInfo();
					$childRec = $childInfoArr[$i];
		
					//$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$childRec["firstname"].' '.$childRec["lastname"].','.$childRec["gender"].','.$childRec["age"].','.$childRec["dietrest"].','.$childRec["allergies"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$childRec["firstname"].' '.$childRec["lastname"].','.$childRec["gender"].','.$childRec["age"].','.$childRec["dietrest"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
			}

			$numCHYK = $ms_registration_value->getNumCHYKRegistered();
			if ($numCHYK > 0)
			{
				$message .= '<tr><td width="250">#CHYK Attendees:</td><td>' . $numCHYK . '</td></tr>';
				if ($ms_registration_value->getCHYKRefFirstName() != "")
				{
						$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-Referrer: '.$ms_registration_value->getCHYKRefFirstName().' '.$ms_registration_value->getCHYKRefLastName().'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
				
				for($i=0; $i<$numCHYK; $i++)
				{
					$chykInfoArr = $ms_registration_value->getCHYKInfo();
					$chykRec = $chykInfoArr[$i];
		
					//$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$childRec["firstname"].' '.$childRec["lastname"].','.$childRec["gender"].','.$childRec["age"].','.$childRec["dietrest"].','.$childRec["allergies"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$childRec["firstname"].' '.$childRec["lastname"].','.$childRec["gender"].','.$childRec["age"].','.$childRec["dietrest"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
			}

			$message .= '<tr><td width="250">Total Attendees:</td><td>' . $ms_registration_value->getTotalNumRegistered() . '</td></tr>';

			$snwc = $ms_registration_value->getSpecialNeedsWheelchair();
			$snrm = $ms_registration_value->getSpecialNeedsRoom();
			$sr = $ms_registration_value->getSpecialRequests();
	
			if (($snwc > 0) || ($snrm > 0) | ($sr != ""))
			{
				$message .= '<tr><td width="250">Special Requests:</td></tr>';
				if ($snwc > 0)
				{
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-Wheelchair Requested</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->Wheelchair Requested</br></font>','tmp',array('class'=>'snwc','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 400px;')) );
				}
	
				if ($snrm > 0)
				{
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-Handicapped Accessible Room Requested</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->Handicapped Accessible Room Requested</br></font>','tmp',array('class'=>'snrm','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 450px;')) );
				}

				if ($sr != "")
				{
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$sr.'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->Handicapped Accessible Room Requested</br></font>','tmp',array('class'=>'snrm','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 450px;')) );
				}
			}

			$dayname = array('Monday, July 30<sup>th</sup>','Tuesday, July 31<sup>st</sup>','Wednesday, Ausgust 1<sup>st</sup>','Thursday, August 2<sup>nd</sup>','Friday, August 3<sup>rd</sup>');
			if ($ms_registration_value->getNumBiksha() > 0)
			{
				$message .= '<tr><td width="250">#Bhiksha Sponsorships:</td><td>' . $ms_registration_value->getNumBiksha() . '</td></tr>';
				$eventname = array('Morning Bhiksha','Lunch Bhiksha','Evening Bhiksha');
				for($i=0; $i<$ms_registration_value->getNumBiksha(); $i++)
				{
					$bikshaInfoArr = $ms_registration_value->getBikshaInfo();
					$bikshaRec = $bikshaInfoArr[$i];
					$dayid = intval($bikshaRec["dayid"]);
					$eventid = intval($bikshaRec["eventid"]);
		
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: -10px 0 4px 10px; width: 300px;')) );
				}
			}

			if ($ms_registration_value->getNumArathi() > 0)
			{
				$message .= '<tr><td width="250">#Arathi Sponsorships:</td><td>' . $ms_registration_value->getNumArathi() . '</td></tr>';
				$eventname = array('Morning Arathi','Lunch Arathi','Evening Arathi');
				for($i=0; $i<$ms_registration_value->getNumArathi(); $i++)
				{
					$arathiInfoArr = $ms_registration_value->getArathiInfo();
					$arathiRec = $arathiInfoArr[$i];
					$dayid = intval($arathiRec["dayid"]);
					$eventid = intval($arathiRec["eventid"]);
		
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: -10px 0 4px 10px; width: 300px;')) );
				}
			}

			$message .= '<tr><td width="250">Registration Fee:</td><td>$' . $ms_registration_value->getRegistrationFee() . '</td></tr>';
			$message .= '<tr><td width="250">Sponsorship:</td><td>$' . $ms_registration_value->getSponsorship() . '</td></tr>';
			$message .= '<tr><td width="250">Teacher Discount:</td><td><font color = "red">$(' . (100*$ms_registration_value->getIsTeacher()) . ')</font></td></tr>';
			$message .= '<tr><td width="250">Total Amount:</td><td>$' . $ms_registration_value->getTotalRegistrationFee() . '</td></tr>';
			$message .= '<tr><td width="250">Paypal Response:</td><td>' . $paypal_response . '</td></tr>';
			$message .= '<tr><td width="250">Please contact Paypal or your credit card issuer</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<table border="0">';
			$message .= '<p>If you have any questions, please contact us with your <u>Registration Code</u>.</p>';
			$message .= '<tr><td width="120"><b>Phone:</b> </td><td>Toll-Free 1-866-RAMDOOT</td></tr>';
			$message .= '<tr><td width="120"><b>Email:</b> </td><td>registration@chinmayamahasamadhi.org</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<p>Sincerely,</p>';
			$message .= '<p>Registration Team</p>';
			$message .= '<p>Chinmaya Mission Boston<br /></p>';
			
			$this->load->library('email');
			$this->email->set_newline("\r\n");
			
			$config['protocol'] = $this->config->item('email_smtp_protocol');
			$config['smtp_host'] = $this->config->item('email_smtp_host');
			$config['smtp_user'] = $this->config->item('email_smtp_user');
			$config['smtp_pass'] = $this->config->item('email_smtp_pass');
			$config['smtp_port'] = $this->config->item('email_smtp_port');
			$config['mailtype'] = $this->config->item('email_smtp_mailtype');
	
			$this->email->initialize($config);
	
			$this->email->from($this->config->item('email_smtp_user'), $this->config->item('email_smtp_user_name'));
			$this->email->to( $ms_registration_value->getEmail() );
			$this->email->cc('');
			$this->email->bcc('cmbproject@gmail.com');
			
			$this->email->subject('Paypal/Credit Card Payment Request Failed for ' . $desc .' '. $curyear);
			$this->email->message($message);
			
			$this->email->send();
		}

		//Confirms registration after payment is confirmed through Paypal ipn
		public function sendEventRegistrationConfirmEmailPaypal( $ms_registration_value, $regcode, $desc, $curyear, $paypal_txn_id )
		{
			$this->load->library('encrypt');

			$ms_registration_value = Mahasamadhi_registration_value::cast($ms_registration_value);
			$desc = $this->getEventName( 1 );
			
			$message = '';
			$message .= '<p><b>You have Been Registered for ' . $curyear . ' ' . $desc.'</b></p>';
			$message .= '<p>Hari OM ' . $ms_registration_value->getFirstName() . 'ji,</p>';
			$message .= '<p>Your registration for ' . $desc . ' ' . $curyear . ' has been confirmed:</p>';
			$message .= '<p>';
			$message .= '<table border="0">';
			$message .= '<tr><td width="250">Registration Code:</td><td><b>' . $regcode . '</b></td></tr>';
			$message .= '<tr><td width="250">Registration Type:</td><td>' . $ms_registration_value->getRegistrationTypeDescription() . '</td></tr>';
			$message .= '<tr><td width="250">Occupancy:</td><td>' . $ms_registration_value->getRegistrationCaseDescription() . '</td></tr>';
			$message .= '<tr><td width="250">Primary Contact Name:</td><td>' . $ms_registration_value->getFirstName() . ' ' . $ms_registration_value->getLastName() . '</td></tr>';
			$message .= '<tr><td width="250">Email:</td><td>' . $ms_registration_value->getEmail() . '</td></tr>';
			$message .= '<tr><td width="250">Phone:</td><td>' . $ms_registration_value->getPhone() . '</td></tr>';
			$message .= '<tr><td width="250">Address1:</td><td>' . $ms_registration_value->getAddress() . '</td></tr>';
			$message .= '<tr><td width="250">Address2:</td><td>' . $ms_registration_value->getAddress1() . '</td></tr>';
			$message .= '<tr><td width="250">City:</td><td>' . $ms_registration_value->getCity() . '</td></tr>';
			$message .= '<tr><td width="250">State/Province:</td><td>' . $ms_registration_value->getState() . '</td></tr>';
			$message .= '<tr><td width="250">Country:</td><td>' . $ms_registration_value->getCountry() . '</td></tr>';
			$message .= '<tr><td width="250">Postal Code:</td><td>' . $ms_registration_value->getZip() . '</td></tr>';

			$needacc = $ms_registration_value->getNeedAccommodation();
			if ($needacc == 0)
			{
				$message .= '<tr><td width="250">Accommodation Not Required</td><td></td></tr>';
			}

			$numAdult = $ms_registration_value->getNumAdultRegistered();
			if ($numAdult > 0)
			{
				$message .= '<tr><td width="250">#Adult Attendees:</td><td>' . $numAdult . '</td></tr>';
				for($i=0; $i<$numAdult; $i++)
				{
					$adultInfoArr = $ms_registration_value->getAdultInfo();
					$adultRec = $adultInfoArr[$i];
		
					//$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$adultRec["firstname"].' '.$adultRec["lastname"].','.$adultRec["gender"].','.$adultRec["dietrest"].','.$adultRec["allergies"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$adultRec["firstname"].' '.$adultRec["lastname"].','.$adultRec["gender"].','.$adultRec["dietrest"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
			}
			
			$numChild = $ms_registration_value->getNumChildRegistered();
			if ($numChild > 0)
			{
				$message .= '<tr><td width="250">#Child Attendees:</td><td>' . $numChild . '</td></tr>';
				for($i=0; $i<$numChild; $i++)
				{
					$childInfoArr = $ms_registration_value->getChildInfo();
					$childRec = $childInfoArr[$i];
		
					//$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$childRec["firstname"].' '.$childRec["lastname"].','.$childRec["gender"].','.$childRec["age"].','.$childRec["dietrest"].','.$childRec["allergies"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$childRec["firstname"].' '.$childRec["lastname"].','.$childRec["gender"].','.$childRec["age"].','.$childRec["dietrest"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
			}

			$numCHYK = $ms_registration_value->getNumCHYKRegistered();
			if ($numCHYK > 0)
			{
				$message .= '<tr><td width="250">#CHYK Attendees:</td><td>' . $numCHYK . '</td></tr>';
				if ($ms_registration_value->getCHYKRefFirstName() != "")
				{
						$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-Referrer: '.$ms_registration_value->getCHYKRefFirstName().' '.$ms_registration_value->getCHYKRefLastName().'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
				
				for($i=0; $i<$numCHYK; $i++)
				{
					$chykInfoArr = $ms_registration_value->getCHYKInfo();
					$chykRec = $chykInfoArr[$i];
		
					//$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$chykRec["firstname"].' '.$chykRec["lastname"].','.$chykRec["gender"].','.$chykRec["dietrest"].','.$chykRec["allergies"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$chykRec["firstname"].' '.$chykRec["lastname"].','.$chykRec["gender"].','.$chykRec["dietrest"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
			}

			$message .= '<tr><td width="250">Total Attendees:</td><td>' . $ms_registration_value->getTotalNumRegistered() . '</td></tr>';

			$snwc = $ms_registration_value->getSpecialNeedsWheelchair();
			$snrm = $ms_registration_value->getSpecialNeedsRoom();
			$sr = $ms_registration_value->getSpecialRequests();
	
			if (($snwc > 0) || ($snrm > 0) | ($sr != ""))
			{
				$message .= '<tr><td width="250">Special Requests:</td></tr>';
				if ($snwc > 0)
				{
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-Wheelchair Requested</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->Wheelchair Requested</br></font>','tmp',array('class'=>'snwc','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 400px;')) );
				}
	
				if ($snrm > 0)
				{
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-Handicapped Accessible Room Requested</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->Handicapped Accessible Room Requested</br></font>','tmp',array('class'=>'snrm','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 450px;')) );
				}

				if ($sr != "")
				{
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$sr.'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->Handicapped Accessible Room Requested</br></font>','tmp',array('class'=>'snrm','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 450px;')) );
				}
			}

			$dayname = array('Monday, July 30<sup>th</sup>','Tuesday, July 31<sup>st</sup>','Wednesday, August 1<sup>st</sup>','Thursday, August 2<sup>nd</sup>','Friday, August 3<sup>rd</sup>');
			if ($ms_registration_value->getNumBiksha() > 0)
			{
				$message .= '<tr><td width="250">#Bhiksha Sponsorships:</td><td>' . $ms_registration_value->getNumBiksha() . '</td></tr>';
				$eventname = array('Morning Bhiksha','Lunch Bhiksha','Evening Bhiksha');
				for($i=0; $i<$ms_registration_value->getNumBiksha(); $i++)
				{
					$bikshaInfoArr = $ms_registration_value->getBikshaInfo();
					$bikshaRec = $bikshaInfoArr[$i];
					$dayid = intval($bikshaRec["dayid"]);
					$eventid = intval($bikshaRec["eventid"]);
		
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: -10px 0 4px 10px; width: 300px;')) );
				}
			}

			if ($ms_registration_value->getNumArathi() > 0)
			{
				$message .= '<tr><td width="250">#Arathi Sponsorships:</td><td>' . $ms_registration_value->getNumArathi() . '</td></tr>';
				$eventname = array('Morning Arathi','Lunch Arathi','Evening Arathi');
				for($i=0; $i<$ms_registration_value->getNumArathi(); $i++)
				{
					$arathiInfoArr = $ms_registration_value->getArathiInfo();
					$arathiRec = $arathiInfoArr[$i];
					$dayid = intval($arathiRec["dayid"]);
					$eventid = intval($arathiRec["eventid"]);
		
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: -10px 0 4px 10px; width: 300px;')) );
				}
			}

			$message .= '<tr><td width="250">Registration Fee:</td><td>$' . $ms_registration_value->getRegistrationFee() . '</td></tr>';
			$message .= '<tr><td width="250">Sponsorship:</td><td>$' . $ms_registration_value->getSponsorship() . '</td></tr>';
			$message .= '<tr><td width="250">Teacher Discount:</td><td><font color = "red">$(' . (100*$ms_registration_value->getIsTeacher()) . ')</font></td></tr>';
			$message .= '<tr><td width="250">Total Amount:</td><td>$' . $ms_registration_value->getTotalRegistrationFee() . '</td></tr>';
			$message .= '<tr><td width="250">Paypal Transaction ID:</td><td>' . $paypal_txn_id . '</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<p>If you have any questions, please contact us with your <u>Registration Code</u>.</p>';
			$message .= '<table border="0">';
			$message .= '<tr><td width="120"><b>Phone:</b> </td><td>Toll-Free 1-866-RAMDOOT</td></tr>';
			$message .= '<tr><td width="120"><b>Email:</b> </td><td>registration@chinmayamahasamadhi.org</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<p>Sincerely,</p>';
			$message .= '<p>Registration Team</p>';
			$message .= '<p>Chinmaya Mission Boston<br /></p>';
			
			$this->load->library('email');
			$this->email->set_newline("\r\n");
			
			$config['protocol'] = $this->config->item('email_smtp_protocol');
			$config['smtp_host'] = $this->config->item('email_smtp_host');
			$config['smtp_user'] = $this->config->item('email_smtp_user');
			$config['smtp_pass'] = $this->config->item('email_smtp_pass');
			$config['smtp_port'] = $this->config->item('email_smtp_port');
			$config['mailtype'] = $this->config->item('email_smtp_mailtype');
	
			$this->email->initialize($config);
	
			$this->email->from($this->config->item('email_smtp_user'), $this->config->item('email_smtp_user_name'));
			$this->email->to( $ms_registration_value->getEmail() );
			$this->email->cc('');
			$this->email->bcc('cmbproject@gmail.com');
			
			$this->email->subject('Registration confirmation for ' . $desc .' '. $curyear);
			$this->email->message($message);
			
			$this->email->send();
		}

		//Email with information about sending check after person has chosen to pay by check
		public function sendEventRegistrationByCheckEmail( $ms_registration_value, $regcode, $desc, $curyear )
		{
			$ms_registration_value = Mahasamadhi_registration_value::cast($ms_registration_value);
			
			$message = '';
			$message .= '<p>Hari OM ' . $ms_registration_value->getFirstName() . 'ji,</p>';
			$message .= '<p>We received your registration request with payment by <u>check</u> for ' . $desc . ' '. $curyear .':</p>';
			$message .= '<p>';
			$message .= '<table border="0">';
			$message .= '<tr><td width="250">Registration Code:</td><td><b>' . $regcode . '</b></td></tr>';
			$message .= '<tr><td width="250">Registration Type:</td><td>' . $ms_registration_value->getRegistrationTypeDescription() . '</td></tr>';
			$message .= '<tr><td width="250">Occupancy:</td><td>' . $ms_registration_value->getRegistrationCaseDescription() . '</td></tr>';
			$message .= '<tr><td width="250">Primary Contact Name:</td><td>' . $ms_registration_value->getFirstName() . ' ' . $ms_registration_value->getLastName() . '</td></tr>';
			$message .= '<tr><td width="250">Email:</td><td>' . $ms_registration_value->getEmail() . '</td></tr>';
			$message .= '<tr><td width="250">Phone:</td><td>' . $ms_registration_value->getPhone() . '</td></tr>';
			$message .= '<tr><td width="250">Address1:</td><td>' . $ms_registration_value->getAddress() . '</td></tr>';
			$message .= '<tr><td width="250">Address2:</td><td>' . $ms_registration_value->getAddress1() . '</td></tr>';
			$message .= '<tr><td width="250">City:</td><td>' . $ms_registration_value->getCity() . '</td></tr>';
			$message .= '<tr><td width="250">State/Province:</td><td>' . $ms_registration_value->getState() . '</td></tr>';
			$message .= '<tr><td width="250">Country:</td><td>' . $ms_registration_value->getCountry() . '</td></tr>';
			$message .= '<tr><td width="250">Postal Code:</td><td>' . $ms_registration_value->getZip() . '</td></tr>';

			$needacc = $ms_registration_value->getNeedAccommodation();
			if ($needacc == 0)
			{
				$message .= '<tr><td width="250">Accommodation Not Required</td><td></td></tr>';
			}

			$numAdult = $ms_registration_value->getNumAdultRegistered();
			if ($numAdult > 0)
			{
				$message .= '<tr><td width="250">#Adult Attendees:</td><td>' . $numAdult . '</td></tr>';
				for($i=0; $i<$numAdult; $i++)
				{
					$adultInfoArr = $ms_registration_value->getAdultInfo();
					$adultRec = $adultInfoArr[$i];
		
					//$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$adultRec["firstname"].' '.$adultRec["lastname"].','.$adultRec["gender"].','.$adultRec["dietrest"].','.$adultRec["allergies"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$adultRec["firstname"].' '.$adultRec["lastname"].','.$adultRec["gender"].','.$adultRec["dietrest"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
			}
			
			$numChild = $ms_registration_value->getNumChildRegistered();
			if ($numChild > 0)
			{
				$message .= '<tr><td width="250">#Child Attendees:</td><td>' . $numChild . '</td></tr>';
				for($i=0; $i<$numChild; $i++)
				{
					$childInfoArr = $ms_registration_value->getChildInfo();
					$childRec = $childInfoArr[$i];
		
					//$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$childRec["firstname"].' '.$childRec["lastname"].','.$childRec["gender"].','.$childRec["age"].','.$childRec["dietrest"].','.$childRec["allergies"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$childRec["firstname"].' '.$childRec["lastname"].','.$childRec["gender"].','.$childRec["age"].','.$childRec["dietrest"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
			}

			$numCHYK = $ms_registration_value->getNumCHYKRegistered();
			if ($numCHYK > 0)
			{
				$message .= '<tr><td width="250">#CHYK Attendees:</td><td>' . $numCHYK . '</td></tr>';
				if ($ms_registration_value->getCHYKRefFirstName() != "")
				{
						$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-Referrer: '.$ms_registration_value->getCHYKRefFirstName().' '.$ms_registration_value->getCHYKRefLastName().'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
				
				for($i=0; $i<$numCHYK; $i++)
				{
					$chykInfoArr = $ms_registration_value->getCHYKInfo();
					$chykRec = $chykInfoArr[$i];
		
					//$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$chykRec["firstname"].' '.$chykRec["lastname"].','.$chykRec["gender"].','.$chykRec["dietrest"].','.$chykRec["allergies"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$chykRec["firstname"].' '.$chykRec["lastname"].','.$chykRec["gender"].','.$chykRec["dietrest"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
			}

			$message .= '<tr><td width="250">Total Attendees:</td><td>' . $ms_registration_value->getTotalNumRegistered() . '</td></tr>';

			$snwc = $ms_registration_value->getSpecialNeedsWheelchair();
			$snrm = $ms_registration_value->getSpecialNeedsRoom();
			$sr = $ms_registration_value->getSpecialRequests();
	
			if (($snwc > 0) || ($snrm > 0) | ($sr != ""))
			{
				$message .= '<tr><td width="250">Special Requests:</td></tr>';
				if ($snwc > 0)
				{
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-Wheelchair Requested</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->Wheelchair Requested</br></font>','tmp',array('class'=>'snwc','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 400px;')) );
				}
	
				if ($snrm > 0)
				{
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-Handicapped Accessible Room Requested</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->Handicapped Accessible Room Requested</br></font>','tmp',array('class'=>'snrm','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 450px;')) );
				}

				if ($sr != "")
				{
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$sr.'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->Handicapped Accessible Room Requested</br></font>','tmp',array('class'=>'snrm','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 450px;')) );
				}
			}

			$dayname = array('Monday, July 30<sup>th</sup>','Tuesday, July 31<sup>st</sup>','Wednesday, August 1<sup>st</sup>','Thursday, August 2<sup>nd</sup>','Friday, August 3<sup>rd</sup>');
			if ($ms_registration_value->getNumBiksha() > 0)
			{
				$message .= '<tr><td width="250">#Bhiksha Sponsorships:</td><td>' . $ms_registration_value->getNumBiksha() . '</td></tr>';
				$eventname = array('Morning Bhiksha','Lunch Bhiksha','Evening Bhiksha');
				for($i=0; $i<$ms_registration_value->getNumBiksha(); $i++)
				{
					$bikshaInfoArr = $ms_registration_value->getBikshaInfo();
					$bikshaRec = $bikshaInfoArr[$i];
					$dayid = intval($bikshaRec["dayid"]);
					$eventid = intval($bikshaRec["eventid"]);
		
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: -10px 0 4px 10px; width: 300px;')) );
				}
			}

			if ($ms_registration_value->getNumArathi() > 0)
			{
				$message .= '<tr><td width="250">#Arathi Sponsorships:</td><td>' . $ms_registration_value->getNumArathi() . '</td></tr>';
				$eventname = array('Morning Arathi','Lunch Arathi','Evening Arathi');
				for($i=0; $i<$ms_registration_value->getNumArathi(); $i++)
				{
					$arathiInfoArr = $ms_registration_value->getArathiInfo();
					$arathiRec = $arathiInfoArr[$i];
					$dayid = intval($arathiRec["dayid"]);
					$eventid = intval($arathiRec["eventid"]);
		
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: -10px 0 4px 10px; width: 300px;')) );
				}
			}

			$message .= '<tr><td width="250">Registration Fee:</td><td>$' . $ms_registration_value->getRegistrationFee() . '</td></tr>';
			$message .= '<tr><td width="250">Sponsorship:</td><td>$' . $ms_registration_value->getSponsorship() . '</td></tr>';
			
			if ($numCHYK == 0)
				$message .= '<tr><td width="250">Teacher Discount:</td><td><font color = "red">$(' . (100*$ms_registration_value->getIsTeacher()) . ')</font></td></tr>';
			
			$message .= '<tr><td width="250">Total Amount Due:</td><td>$' . $ms_registration_value->getTotalRegistrationFee() . '</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<p>Please write a check for <b>$' . $ms_registration_value->getTotalRegistrationFee() . '</b>, payable to <u>Chinmaya Mission Boston</u>. Mail the check to:</p>';
			$message .= '<table border="0">';
			$message .= '<tr><td width="250"></td><td>ATTN: '.$desc.' '.$curyear.' Registration</td></tr>';
			$message .= '<tr><td width="250"></td><td>Chinmaya Mission Boston</td></tr>';
			$message .= '<tr><td width="250"></td><td>1 Union Street</td></tr>';
			$message .= '<tr><td width="250"></td><td>Andover, MA  01810</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<p>If you have any questions, please contact us with your <u>Registration Code</u>.</p>';
			$message .= '<table border="0">';
			$message .= '<tr><td width="120"><b>Phone:</b></td><td>Toll-Free 1-866-RAMDOOT</td></tr>';
			$message .= '<tr><td width="120"><b>Email:</b></td><td>registration@chinmayamahasamadhi.org</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<p>Sincerely,</p>';
			$message .= '<p>Registration Team</p>';
			$message .= '<p>Chinmaya Mission Boston<br /></p>';
			
			//echo($message);
			//die;
			$this->load->library('email');
			$this->email->set_newline("\r\n");
			
			$config['protocol'] = $this->config->item('email_smtp_protocol');
			$config['smtp_host'] = $this->config->item('email_smtp_host');
			$config['smtp_user'] = $this->config->item('email_smtp_user');
			$config['smtp_pass'] = $this->config->item('email_smtp_pass');
			$config['smtp_port'] = $this->config->item('email_smtp_port');
			$config['mailtype'] = $this->config->item('email_smtp_mailtype');
	
			$this->email->initialize($config);
	
			$this->email->from($this->config->item('email_smtp_user'), $this->config->item('email_smtp_user_name'));
			$this->email->to( $ms_registration_value->getEmail() );
			$this->email->cc('cmbproject@gmail.com');
			
			$this->email->subject('Payment by check for ' . $desc . ' '. $curyear);
			$this->email->message($message);
			
			$this->email->send();
		}	

		//Confirms registration after payment via check is released
		public function sendEventRegistrationCheckConfirmEmail( $ms_registration_value, $curyear)
		{
			$this->load->library('encrypt');

			$ms_registration_value = Mahasamadhi_registration_value::cast($ms_registration_value);
			
			$desc = $this->getEventName( 1 );
			
			$message = '';
			$message .= '<p><b>You have Been Registered for ' . $desc . ' ' . $curyear.'</b></p>';
			$message .= '<p>Hari OM ' . $ms_registration_value->getFirstName() . 'ji,</p>';
			$message .= '<p>Your registration for ' .$desc . ' '.$curyear.' has been confirmed:</p>';
			$message .= '<p>';
			$message .= '<table border="0">';
			$message .= '<tr><td width="250">Registration Code:</td><td><b>' . $ms_registration_value->getRegCode() . '</b></td></tr>';
			$message .= '<tr><td width="250">Registration Type:</td><td>' . $ms_registration_value->getRegistrationTypeDescription() . '</td></tr>';
			$message .= '<tr><td width="250">Occupancy:</td><td>' . $ms_registration_value->getRegistrationCaseDescription() . '</td></tr>';
			$message .= '<tr><td width="250">Name:</td><td>' . $ms_registration_value->getFirstName() . ' ' . $ms_registration_value->getLastName() . '</td></tr>';
			$message .= '<tr><td width="250">Email:</td><td>' . $ms_registration_value->getEmail() . '</td></tr>';
			$message .= '<tr><td width="250">Phone:</td><td>' . $ms_registration_value->getPhone() . '</td></tr>';
			$message .= '<tr><td width="250">Address1:</td><td>' . $ms_registration_value->getAddress() . '</td></tr>';
			$message .= '<tr><td width="250">Address2:</td><td>' . $ms_registration_value->getAddress1() . '</td></tr>';
			$message .= '<tr><td width="250">City:</td><td>' . $ms_registration_value->getCity() . '</td></tr>';
			$message .= '<tr><td width="250">State/Province:</td><td>' . $ms_registration_value->getState() . '</td></tr>';
			$message .= '<tr><td width="250">Country:</td><td>' . $ms_registration_value->getCountry() . '</td></tr>';
			$message .= '<tr><td width="250">Postal Code:</td><td>' . $ms_registration_value->getZip() . '</td></tr>';
			
			$needacc = $ms_registration_value->getNeedAccommodation();
			if ($needacc == 0)
			{
				$message .= '<tr><td width="250">Accommodation Not Required</td><td></td></tr>';
			}

			$numAdult = $ms_registration_value->getNumAdultRegistered();
			if ($numAdult > 0)
			{
				$message .= '<tr><td width="250">#Adult Attendees:</td><td>' . $numAdult . '</td></tr>';
				for($i=0; $i<$numAdult; $i++)
				{
					$adultInfoArr = $ms_registration_value->getAdultInfo();
					$adultRec = $adultInfoArr[$i];
		
					//$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$adultRec["firstname"].' '.$adultRec["lastname"].','.$adultRec["gender"].','.$adultRec["dietrest"].','.$adultRec["allergies"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$adultRec["firstname"].' '.$adultRec["lastname"].','.$adultRec["gender"].','.$adultRec["dietrest"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
			}
			
			$numChild = $ms_registration_value->getNumChildRegistered();
			if ($numChild > 0)
			{
				$message .= '<tr><td width="250">#Child Attendees:</td><td>' . $numChild . '</td></tr>';
				for($i=0; $i<$numChild; $i++)
				{
					$childInfoArr = $ms_registration_value->getChildInfo();
					$childRec = $childInfoArr[$i];
		
					//$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$childRec["firstname"].' '.$childRec["lastname"].','.$childRec["gender"].','.$childRec["age"].','.$childRec["dietrest"].','.$childRec["allergies"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$childRec["firstname"].' '.$childRec["lastname"].','.$childRec["gender"].','.$childRec["age"].','.$childRec["dietrest"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
			}

			$numCHYK = $ms_registration_value->getNumCHYKRegistered();
			if ($numCHYK > 0)
			{
				$message .= '<tr><td width="250">#CHYK Attendees:</td><td>' . $numCHYK . '</td></tr>';
				if ($ms_registration_value->getCHYKRefFirstName() != "")
				{
						$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-Referrer: '.$ms_registration_value->getCHYKRefFirstName().' '.$ms_registration_value->getCHYKRefLastName().'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
				
				for($i=0; $i<$numCHYK; $i++)
				{
					$chykInfoArr = $ms_registration_value->getCHYKInfo();
					$chykRec = $chykInfoArr[$i];
		
					//$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$chykRec["firstname"].' '.$chykRec["lastname"].','.$chykRec["gender"].','.$chykRec["dietrest"].','.$chykRec["allergies"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$chykRec["firstname"].' '.$chykRec["lastname"].','.$chykRec["gender"].','.$chykRec["dietrest"].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
				}
			}

			$message .= '<tr><td width="250">Total Attendees:</td><td>' . $ms_registration_value->getTotalNumRegistered() . '</td></tr>';

			$snwc = $ms_registration_value->getSpecialNeedsWheelchair();
			$snrm = $ms_registration_value->getSpecialNeedsRoom();
			$sr = $ms_registration_value->getSpecialRequests();
	
			if (($snwc > 0) || ($snrm > 0) | ($sr != ""))
			{
				$message .= '<tr><td width="250">Special Requests:</td></tr>';
				if ($snwc > 0)
				{
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-Wheelchair Requested</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->Wheelchair Requested</br></font>','tmp',array('class'=>'snwc','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 400px;')) );
				}
	
				if ($snrm > 0)
				{
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-Handicapped Accessible Room Requested</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->Handicapped Accessible Room Requested</br></font>','tmp',array('class'=>'snrm','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 450px;')) );
				}

				if ($sr != "")
				{
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$sr.'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->Handicapped Accessible Room Requested</br></font>','tmp',array('class'=>'snrm','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 450px;')) );
				}
			}

			$dayname = array('Monday, July 30<sup>th</sup>','Tuesday, July 31<sup>st</sup>','Wednesday, August 1<sup>st</sup>','Thursday, August 2<sup>nd</sup>','Friday, August 3<sup>rd</sup>');
			if ($ms_registration_value->getNumBiksha() > 0)
			{
				$message .= '<tr><td width="250">#Bhiksha Sponsorships:</td><td>' . $ms_registration_value->getNumBiksha() . '</td></tr>';
				$eventname = array('Morning Bhiksha','Lunch Bhiksha','Evening Bhiksha');
				for($i=0; $i<$ms_registration_value->getNumBiksha(); $i++)
				{
					$bikshaInfoArr = $ms_registration_value->getBikshaInfo();
					$bikshaRec = $bikshaInfoArr[$i];
					$dayid = intval($bikshaRec["dayid"]);
					$eventid = intval($bikshaRec["eventid"]);
		
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: -10px 0 4px 10px; width: 300px;')) );
				}
			}

			if ($ms_registration_value->getNumArathi() > 0)
			{
				$message .= '<tr><td width="250">#Arathi Sponsorships:</td><td>' . $ms_registration_value->getNumArathi() . '</td></tr>';
				$eventname = array('Morning Arathi','Lunch Arathi','Evening Arathi');
				for($i=0; $i<$ms_registration_value->getNumArathi(); $i++)
				{
					$arathiInfoArr = $ms_registration_value->getArathiInfo();
					$arathiRec = $arathiInfoArr[$i];
					$dayid = intval($arathiRec["dayid"]);
					$eventid = intval($arathiRec["eventid"]);
		
					$message .= '<tr><td width="250">'.form_label('<font size="2" color="blue">-'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: 0px 0 4px 10px; width: 300px;')).'</td></tr>';
					//echo ( form_label('<font size="2" color="blue">->'.$dayname[$dayid-1].' - '.$eventname[$eventid-1].'</font>','tmp',array('class'=>'sncomments','style'=>'clear: left; display: block; float: left; vertical-align: middle; padding: 0; margin: -10px 0 4px 10px; width: 300px;')) );
				}
			}

			$message .= '<tr><td width="250">Registration Fee:</td><td>$' . $ms_registration_value->getRegistrationFee() . '</td></tr>';
			$message .= '<tr><td width="250">Sponsorship:</td><td>$' . $ms_registration_value->getSponsorship() . '</td></tr>';
			$message .= '<tr><td width="250">Teacher Discount:</td><td><font color = "red">$(' . (100*$ms_registration_value->getIsTeacher()) . ')</font></td></tr>';
			$message .= '<tr><td width="250">Total Fee:</td><td>$' . $ms_registration_value->getTotalRegistrationFee() . '</td></tr>';
			$message .= '<tr><td width="250">Check#:</td><td>' . $ms_registration_value->getCheckNum() . '</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<p>If you have any questions, please contact us with your <u>Registration Code</u>.</p>';
			$message .= '<table border="0">';
			$message .= '<tr><td width="120"><b>Phone:</b> </td><td>1-866-RAMDOOT</td></tr>';
			$message .= '<tr><td width="120"><b>Email:</b> </td><td>registration@chinmayamahasamadhi.org</td></tr>';
			$message .= '</table>';
			$message .= '</p>';
			$message .= '<p>Sincerely,</p>';
			$message .= '<p>Registration Team</p>';
			$message .= '<p>Chinmaya Mission Boston<br /></p>';
			
			$this->load->library('email');
			$this->email->set_newline("\r\n");
			
			$config['protocol'] = $this->config->item('email_smtp_protocol');
			$config['smtp_host'] = $this->config->item('email_smtp_host');
			$config['smtp_user'] = $this->config->item('email_smtp_user');
			$config['smtp_pass'] = $this->config->item('email_smtp_pass');
			$config['smtp_port'] = $this->config->item('email_smtp_port');
			$config['mailtype'] = $this->config->item('email_smtp_mailtype');
	
			$this->email->initialize($config);
	
			$this->email->from($this->config->item('email_smtp_user'), $this->config->item('email_smtp_user_name'));
			$this->email->to( $ms_registration_value->getEmail() );
			$this->email->cc('');
			$this->email->bcc('cmbproject@gmail.com');
			
			$this->email->subject('Registration confirmation for ' . $desc .' '. $curyear);
			$this->email->message($message);
			
			$this->email->send();
		}
	}
?>